public void Trump_WideNarrow_Test() { Bench(ExampleText.TRUMP, 10, new[] { new Pair <string, Func <string, string> >("StrConv", targetText => { var s = Strings.StrConv(targetText, VbStrConv.Wide, 0x411); s = Strings.StrConv(s, VbStrConv.Narrow, 0x411); return(s); }), new Pair <string, Func <string, string> >("Kanaxs", targetText => { var s = Kana.ToZenkaku(targetText); s = Kana.ToHankaku(s); return(s); }), new Pair <string, Func <string, string> >("Kanaria", targetText => { return(UcsString.From(targetText) .Wide() .Narrow() .ToString()); }), }); }
public static Yyyymm Parse(string yyyymm, string timeZoneId) { if ("今月".Equals(yyyymm)) { var tz = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); var nowTz = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz); return(Yyyymm.FromDate(nowTz)); } else if ("先月".Equals(yyyymm)) { var tz = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); var nowTz = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz); return(Yyyymm.FromDate(nowTz.AddMonths(-1))); } int year = 0; int month = 0; var hankaku = Kana.ToHankaku(yyyymm); var buf = hankaku.Split('/', '-', '年', '月', '日'); try { if (buf?.Length == 2 || buf?.Length == 3) { year = int.Parse(buf[0]); month = int.Parse(buf[1]); } else if (hankaku.Length >= 4) { year = int.Parse(hankaku.Substring(0, 4)); month = int.Parse(hankaku.Substring(4, 2)); } else { Trace.WriteLine($"Yyyymm parse invalid length - {yyyymm}"); return(Yyyymm.Empty); } if (!(2000 <= year && year <= 3999)) { Trace.WriteLine($"Yyyymm parse failed - year is out of range {yyyymm}"); return(Yyyymm.Empty); } if (!(1 <= month && month <= 12)) { Trace.WriteLine($"Yyyymm parse failed - month is out of range {yyyymm}"); return(Yyyymm.Empty); } return(new Yyyymm(year, month)); } catch (Exception) { Trace.WriteLine($"Yyyymm parse failed - {yyyymm}"); return(Yyyymm.Empty); } }
private static string Clean(string text) { var hankaku = Kana.ToHankaku(text); hankaku = hankaku .Replace(Convert.ToChar(0x0A).ToString(), "") .Replace("\0", "") .Replace("\b", "") .Replace("\n", "") .Replace("\r", "") .Replace("\t", "") .Replace("(", "") .Replace(")", "") .Replace(":", "") ; return(_regex.Replace(hankaku, "")); }
public static Hhmm Parse(string hhmm) { try { int hour = 0; int minute = 0; var hankaku = Kana.ToHankaku(hhmm); var buf = hankaku.Split(':', '-', '時', '分', '秒'); if (buf?.Length == 2 || buf?.Length == 3 || buf?.Length == 4) { hour = int.Parse(buf[0]); minute = int.Parse(buf[1]); } if (hhmm.Length >= 4) { hour = int.Parse(hhmm.Substring(0, 2)); minute = int.Parse(hhmm.Substring(2)); } else { return(Hhmm.Empty); } if (!(0 <= hour && hour <= 36)) { Trace.WriteLine($"Hhmm parse failed - hour is out of range {hhmm}"); return(Hhmm.Empty); } if (!(0 <= minute && minute <= 59)) { Trace.WriteLine($"Hhmm parse failed - minute is out of range {hhmm}"); return(Hhmm.Empty); } return(new Hhmm(hour, minute)); } catch (Exception) { Trace.WriteLine($"Hhmm parse failed - {hhmm}"); return(Hhmm.Empty); } }
// 一行分の縦書きテキストを出力する public static float MakeVerticalLine(PdfContentByte pdfContentByte, string text, float x, float y, float fontSize, int alignment, float vScale, bool tatechuyoko = false, bool isShugo = false) { // index番目の文字を取得 char GetChar(string str, int index) { try { return(str[index]); } catch (IndexOutOfRangeException) { return('_'); } } string zenNum = "0123456789"; string kakkoStart = "(「【『<[〈《〔{"; string kakkoEnd = ")」】』>]〉》〕}"; string rotate = "ー~-:;〜"; string touten = "、。.,.,"; bool asHankaku = false; for (var i = 0; text.Length > i; i++) { char c = text[i]; char prev, next, nextnext; if ((kakkoStart.IndexOf(c) >= 0 || kakkoEnd.IndexOf(c) >= 0 || rotate.IndexOf(c) >= 0) && !isShugo) // 括弧は90度回転させて移動(非集合チラシ) { pdfContentByte.ShowTextAligned(alignment, c.ToString(), 0, -1 * vScale, 1, 0, x + (fontSize / 2), y - (fontSize * vScale / 2), 0); } else if ((kakkoStart.IndexOf(c) >= 0 || kakkoEnd.IndexOf(c) >= 0 || rotate.IndexOf(c) >= 0) && isShugo) // 括弧は90度回転させて移動(集合チラシ) { pdfContentByte.ShowTextAligned(alignment, c.ToString(), 0, -1 * vScale, 1, 0, x + (fontSize / 8), y + (fontSize * vScale * 7 / 8), 0); } else if (touten.IndexOf(c) >= 0) // 読点 { pdfContentByte.ShowTextAligned(alignment, c.ToString(), 1, 0, 0, vScale, x + (fontSize / 2), y + (fontSize * vScale / 2), 0); } else if (zenNum.IndexOf(c) >= 0 && tatechuyoko) // 数字(縦中横の設定) { prev = GetChar(text, i - 1); next = GetChar(text, i + 1); nextnext = GetChar(text, i + 2); if (zenNum.IndexOf(prev) < 0 && zenNum.IndexOf(next) >= 0 && zenNum.IndexOf(nextnext) < 0) { pdfContentByte.ShowTextAligned(alignment, Kana.ToHankaku(c.ToString()), 1, 0, 0, vScale, x - (fontSize / 6), y, 0); pdfContentByte.ShowTextAligned(alignment, Kana.ToHankaku(next.ToString()), 1, 0, 0, vScale, x + (fontSize / 2), y, 0); i++; } else { pdfContentByte.ShowTextAligned(alignment, c.ToString(), 1, 0, 0, vScale, x, y, 0); } } else { pdfContentByte.ShowTextAligned(alignment, c.ToString(), 1, 0, 0, vScale, x, y, 0); } // 半角文字かどうかを判定する next = GetChar(text, i + 1); if (kakkoEnd.IndexOf(c) >= 0 || kakkoStart.IndexOf(next) >= 0 || touten.IndexOf(c) >= 0) { asHankaku = true; } if (asHankaku) { y -= (fontSize * vScale) / 2.0f; } else { y -= fontSize * vScale; } asHankaku = false; } return(y); }
static internal string ToNarrow(this string str) => Kana.ToHankaku(str);
public static Yyyymmdd Parse(string yyyymmdd, string timeZoneId) { try { int year = 0; int month = 0; int day = 0; if ("今日".Equals(yyyymmdd)) { var tz = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); var nowTz = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz); return(Yyyymmdd.FromDate(nowTz)); } else if ("昨日".Equals(yyyymmdd)) { var tz = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); var nowTz = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, tz); return(Yyyymmdd.FromDate(nowTz.AddDays(-1))); } var hankaku = Kana.ToHankaku(yyyymmdd); var buf = hankaku.Split('/', '-', '年', '月', '日'); if (buf?.Length == 3 || buf?.Length == 4) { year = int.Parse(buf[0]); month = int.Parse(buf[1]); day = int.Parse(buf[2]); } else if (hankaku.Length >= 8) { year = int.Parse(hankaku.Substring(0, 4)); month = int.Parse(hankaku.Substring(4, 2)); day = int.Parse(hankaku.Substring(6, 2)); } else { return(Yyyymmdd.Empty); } if (!(2000 <= year && year <= 3999)) { Trace.WriteLine($"Yyyymm parse failed - year is out of range {yyyymmdd}"); return(Yyyymmdd.Empty); } if (!(1 <= month && month <= 12)) { Trace.WriteLine($"Yyyymm parse failed - month is out of range {yyyymmdd}"); return(Yyyymmdd.Empty); } if (!(1 <= day && day <= 31)) { Trace.WriteLine($"Yyyymm parse failed - day is out of range {yyyymmdd}"); return(Yyyymmdd.Empty); } return(new Yyyymmdd(year, month, day)); } catch (Exception) { Trace.WriteLine($"Hhmm parse failed - {yyyymmdd}, timeZone - {timeZoneId}"); return(Yyyymmdd.Empty); } }
/// <summary> /// 全角を半角、カタカナをひらがな、大文字を小文字、に変換した文字列を返却します /// </summary> /// <param name="str">対象の文字列</param> /// <returns>変換後の文字列</returns> private static string ToComparable(this string value) { return(Kana.ToHiragana(Kana.ToHankaku(value.ToLower()))); }