public static string BuildPropertyName(string name, TextCase textCase, bool encode) { if (name.IsNullOrEmpty()) { return(string.Empty); } name = FormatPropertyName(name, textCase); //encode propertyName if (encode) { //force encode. var buffer = StringExtension.GetEncodeString(name, false, true); int length = buffer.Length; var newArray = new char[length + 1]; Array.Copy(buffer, 0, newArray, 0, length); newArray[length] = ':'; return(new string(newArray, 0, length + 1)); } else { return(string.Concat("\"", name, "\":")); } }
private static string Formatter(Guid value, TextCase textCase) { return(string.Format(@"// {0} IMPLEMENT_OLECREATE(<<class>>, <<external_name>>, 0x{1}, 0x{2}, 0x{3}, 0x{4}, 0x{5}, 0x{6}, 0x{7}, 0x{8}, 0x{9}, 0x{10}, 0x{11});", value.GetEnumeratedParts(textCase))); }
internal static object[] GetEnumeratedParts(this Guid aGuid, TextCase testCase) { //Spec out the parts that should be enumerated. var pairs = new[] { new { SkipCount = 0, TakeCount = 4 }, new { SkipCount = 4, TakeCount = 2 }, new { SkipCount = 6, TakeCount = 2 }, new { SkipCount = 8, TakeCount = 1 }, new { SkipCount = 9, TakeCount = 1 }, new { SkipCount = 10, TakeCount = 1 }, new { SkipCount = 11, TakeCount = 1 }, new { SkipCount = 12, TakeCount = 1 }, new { SkipCount = 13, TakeCount = 1 }, new { SkipCount = 14, TakeCount = 1 }, new { SkipCount = 15, TakeCount = 1 }, }; var bytes = aGuid.ToByteArray(); //By virtue of the fact we are working with Guid this should be the case but check anyway. Debug.Assert(bytes.Length == 16); var theParts = pairs.Select(x => bytes.Skip(x.SkipCount) .Take(x.TakeCount).ToHexString().ToTextCase(testCase)); return(new object[] { aGuid.ToString("D").ToTextCase(testCase) } .Concat(theParts).ToArray()); }
public KeywordPattern( string PatternValue, TextCase CompareCase = TextCase.SameCase) : base(PatternValue, DelimClassification.Keyword) { this.CompareCase = CompareCase; }
private static Tuple <bool, int> EqualsText( string Pattern, TextCase CompareCase, string Text, int Ix) { int matchLx = 0; bool doesMatch = false; int remLx = Text.Length - Ix; int patLx = Pattern.Length; if (remLx < patLx) { doesMatch = false; } else if ((CompareCase == TextCase.SameCase) && (Pattern == Text.Substring(Ix, patLx))) { doesMatch = true; matchLx = patLx; } else if ((CompareCase == TextCase.MonoCase) && (Pattern == Text.Substring(Ix, patLx).ToLower())) { doesMatch = true; matchLx = patLx; } else { doesMatch = false; } return(new Tuple <bool, int>(doesMatch, matchLx)); }
private static string Formatter(Guid value, TextCase textCase) { return(string.Format(@"// {0} DEFINE_GUID(<<name>>, 0x{1}, 0x{2}, 0x{3}, 0x{4}, 0x{5}, 0x{6}, 0x{7}, 0x{8}, 0x{9}, 0x{10}, 0x{11});", value.GetEnumeratedParts(textCase))); }
internal static string ToTextCase(this string text, TextCase textCase) { Debug.Assert(TextCaseHandlers.ContainsKey(textCase)); var handler = TextCaseHandlers[textCase]; return(handler(text)); }
private static string Formatter(Guid value, TextCase textCase) { return(string.Format(@"// {0} static const GUID <<name>> = {{ 0x{1}, 0x{2}, 0x{3}, {{ 0x{4}, 0x{5}, 0x{6}, 0x{7}, 0x{8}, 0x{9}, 0x{10}, 0x{11} }} }};", value.GetEnumeratedParts(textCase))); }
public static string CreateName(object text, SerializationSettings settings, TextCase defaultCase) { if (text == null) { return(null); } return(CreateName(text.ToString(), settings, defaultCase)); }
public static string NumeralsDoubleToTxt(double sourceNumber, int @decimal, TextCase _case, bool firstCapital) { var decNum = (long)Math.Round(sourceNumber * Math.Pow(10, @decimal)) % (long)(Math.Pow(10, @decimal)); var s = String.Format(" {0} целых {1} сотых", NumeralsToTxt((long)sourceNumber, _case, true, firstCapital), NumeralsToTxt(decNum, _case, true, false)); return(s.Trim()); }
public Writer(SerializationSettings settings, TextCase defaultTextCase) { this.forward = DoWrite; this.Settings = settings ?? new SerializationSettings(); if (this.Settings.TextCase == TextCase.Default) { this.Settings.TextCase = defaultTextCase; } }
public static string NumeralsDoubleToTxt(double _sourceNumber, int _decimal, TextCase _case, bool _firstCapital) { long decNum = (long)Math.Round(_sourceNumber * Math.Pow(10, _decimal)) % (long)(Math.Pow(10, _decimal)); string s = String.Format(" {0} целых {1} сотых", NumeralsToTxt((long)_sourceNumber, _case, true, _firstCapital), NumeralsToTxt((long)decNum, _case, true, false)); return(s.Trim()); }
/// <summary> /// название м-ца /// </summary> /// <param name="_month">с единицы</param> /// <param name="_case"></param> /// <returns></returns> public static string MonthName(int _month, TextCase _case) { string s = ""; if (_month > 0 && _month <= 12 && monthNames.ContainsKey(_case)) { return(monthNames[_case][_month]); } return(s); }
public static string FormatPropertyName(string value, TextCase textCase) { switch (textCase) { case TextCase.CamelCase: return(value.ToCamelCase()); case TextCase.SnakeCase: return(value.ToLowercaseUnderscore()); default: return(value); } }
private static string BuildCharacterSet(TextCase textCase) { var characterSet = new StringBuilder(NumericCharacterSet); if (textCase == TextCase.Upper || textCase == TextCase.Mixed) { characterSet.Append(UpperCaseCharacterSet); } if (textCase == TextCase.Lower || textCase == TextCase.Mixed) { characterSet.Append(LowerCaseCharacterSet); } return(characterSet.ToString()); }
/// <summary> /// название м-ца /// </summary> /// <param name="month">с единицы</param> /// <param name="_case"></param> /// <returns></returns> public static string MonthName(int month, TextCase _case) { var s = ""; if (month > 0 && month <= 12) { switch (_case) { case TextCase.Genitive: s = MonthNamesGenitive[month]; break; } } return(s); }
public static string CreateName(string text, SerializationSettings settings, TextCase defaultCase) { if (text == null) { return(null); } if (text.StartsWith("\"") || text.StartsWith("'")) { text = text.Substring(1, text.Length - 2); } var textCase = (settings.TextCase == TextCase.Default) ? defaultCase : settings.TextCase; return(text.ChangeCase(textCase)); }
/// <summary> /// название м-ца /// </summary> /// <param name="_month">с единицы</param> /// <param name="_case"></param> /// <returns></returns> public static string MonthName(int _month, TextCase _case) { string s = ""; if (_month > 0 && _month <= 12) { switch (_case) { case TextCase.Genitive: s = monthNamesGenitive[_month]; break; } } return(s); }
/// <summary> /// название м-ца /// </summary> /// <param name="month">с единицы</param> /// <param name="textcase"></param> /// <returns></returns> public static string MonthName(int month, TextCase textcase) { string s = ""; if (month > 0 && month <= 12) { switch (textcase) { case TextCase.Genitive: s = monthNamesGenitive[month]; break; default: throw new NotImplementedException(textcase.ToString()); } } return(s); }
public static MvcHtmlString TextBoxFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, object htmlAttributes, TextCase textcase) { var values = new RouteValueDictionary(htmlAttributes); switch (textcase) { case TextCase.toLower: values.Add("case", "lower"); break; case TextCase.toUpper: values.Add("case", "upper"); break; default: break; } return(htmlHelper.TextBoxFor <TModel, TProperty>(expression, values)); }
public static string ChangeCase(this string sentence, TextCase textCase) { var isPreserveData = textCase.HasFlag(TextCase.PreserveSpecialCharacters); if (isPreserveData) { var separators = delimiters.Substring(1); var matches = Regex.Matches(sentence, $"([^{separators}]+)([{separators}]+)?"); var sentences = ( from match in matches.Cast <Match>() select new[] { DoChangeCase(match.Groups[1].Value, textCase), match.Groups[2].Value } ).SelectMany(); return(string.Join("", sentences)); } else { return(DoChangeCase(sentence, textCase)); } }
//AF added public string ConvertCase(string item, TextCase decorationCase) { if (string.IsNullOrWhiteSpace(item)) { return(""); } switch (decorationCase) { case TextCase.None: return(item); case TextCase.Upper: return(new CultureInfo(_workContext.WorkingLanguage.LanguageCulture, false).TextInfo.ToUpper(item)); case TextCase.Lower: return(new CultureInfo(_workContext.WorkingLanguage.LanguageCulture, false).TextInfo.ToLower(item)); case TextCase.Capitalize: return(new CultureInfo(_workContext.WorkingLanguage.LanguageCulture, false).TextInfo.ToTitleCase(item)); default: return(item); } }
private static string Formatter(Guid value, TextCase textCase) => $@"[assembly: Guid(""{$"{value:D}".ToTextCase(textCase)}"")]";
/// <summary> /// реализовано для падежей: именительный (nominative), родительный (Genitive), винительный (accusative) /// </summary> /// <param name="_sourceNumber"></param> /// <param name="_case"></param> /// <param name="_isMale"></param> /// <param name="_firstCapital"></param> /// <returns></returns> public static string NumeralsToTxt(long _sourceNumber, TextCase _case, bool _isMale, bool _firstCapital) { string s = ""; long number = _sourceNumber; int remainder; int power = 0; if ((number >= (long)Math.Pow(10, 15)) || number < 0) { return(""); } while (number > 0) { remainder = (int)(number % 1000); number = number / 1000; switch (power) { case 12: s = MakeText(remainder, hundreds, tens, from3till19, secondMale, firstMale, trillions) + s; break; case 9: s = MakeText(remainder, hundreds, tens, from3till19, secondMale, firstMale, billions) + s; break; case 6: s = MakeText(remainder, hundreds, tens, from3till19, secondMale, firstMale, millions) + s; break; case 3: switch (_case) { case TextCase.Accusative: s = MakeText(remainder, hundreds, tens, from3till19, secondFemale, firstFemaleAccusative, thousandsAccusative) + s; break; default: s = MakeText(remainder, hundreds, tens, from3till19, secondFemale, firstFemale, thousands) + s; break; } break; default: string[] powerArray = { }; switch (_case) { case TextCase.Genitive: s = MakeText(remainder, hundredsGenetive, tensGenetive, from3till19Genetive, _isMale ? secondMaleGenetive : secondFemaleGenetive, _isMale ? firstMaleGenetive : firstFemale, powerArray) + s; break; case TextCase.Accusative: s = MakeText(remainder, hundreds, tens, from3till19, _isMale ? secondMale : secondFemale, _isMale ? firstMale : firstFemaleAccusative, powerArray) + s; break; default: s = MakeText(remainder, hundreds, tens, from3till19, _isMale ? secondMale : secondFemale, _isMale ? firstMale : firstFemale, powerArray) + s; break; } break; } power += 3; } if (_sourceNumber == 0) { s = zero + " "; } if (s != "" && _firstCapital) { s = s.Substring(0, 1).ToUpper() + s.Substring(1); } return(s.Trim()); }
private static string Formatter(Guid value, TextCase textCase) => $@"<Guid(""{$"{value:D}".ToTextCase(textCase)}"")>";
/// <summary> /// реализовано для падежей: именительный (nominative), родительный (Genitive), винительный (accusative) /// </summary> /// <param name="sourceNumber"></param> /// <param name="_case"></param> /// <param name="isMale"></param> /// <param name="firstCapital"></param> /// <returns></returns> public static string NumeralsToTxt(long sourceNumber, TextCase _case, bool isMale, bool firstCapital) { var s = ""; var number = sourceNumber; var power = 0; if ((number >= (long)Math.Pow(10, 15)) || number < 0) { return(""); } while (number > 0) { var remainder = (int)(number % 1000); number = number / 1000; switch (power) { case 12: s = MakeText(remainder, Hundreds, Tens, From3Till19, SecondMale, FirstMale, Trillions) + s; break; case 9: s = MakeText(remainder, Hundreds, Tens, From3Till19, SecondMale, FirstMale, Billions) + s; break; case 6: s = MakeText(remainder, Hundreds, Tens, From3Till19, SecondMale, FirstMale, Millions) + s; break; case 3: switch (_case) { case TextCase.Accusative: s = MakeText(remainder, Hundreds, Tens, From3Till19, SecondFemale, FirstFemaleAccusative, ThousandsAccusative) + s; break; default: s = MakeText(remainder, Hundreds, Tens, From3Till19, SecondFemale, FirstFemale, Thousands) + s; break; } break; default: string[] powerArray = { }; switch (_case) { case TextCase.Genitive: s = MakeText(remainder, HundredsGenetive, TensGenetive, From3Till19Genetive, isMale ? SecondMaleGenetive : SecondFemaleGenetive, isMale ? FirstMaleGenetive : FirstFemale, powerArray) + s; break; case TextCase.Accusative: s = MakeText(remainder, Hundreds, Tens, From3Till19, isMale ? SecondMale : SecondFemale, isMale ? FirstMale : FirstFemaleAccusative, powerArray) + s; break; default: s = MakeText(remainder, Hundreds, Tens, From3Till19, isMale ? SecondMale : SecondFemale, isMale ? FirstMale : FirstFemale, powerArray) + s; break; } break; } power += 3; } if (sourceNumber == 0) { s = Zero + " "; } if (s != "" && firstCapital) { s = s.Substring(0, 1).ToUpper() + s.Substring(1); } return(s.Trim()); }
public static string GetLocalized <T>(this T entity, Expression <Func <T, string> > keySelector, TextCase decorationCase) where T : BaseEntity, ILocalizedEntity { var workContext = EngineContext.Current.Resolve <IWorkContext>(); var localizedItem = entity.GetLocalized(keySelector, workContext.WorkingLanguage.Id); if (localizedItem == null) { return(null); } switch (decorationCase) { case TextCase.None: return(localizedItem); case TextCase.Upper: return(new CultureInfo(workContext.WorkingLanguage.LanguageCulture, false).TextInfo.ToUpper(localizedItem)); case TextCase.Lower: return(new CultureInfo(workContext.WorkingLanguage.LanguageCulture, false).TextInfo.ToLower(localizedItem)); case TextCase.Capitalize: return(new CultureInfo(workContext.WorkingLanguage.LanguageCulture, false).TextInfo.ToTitleCase(localizedItem)); default: return(localizedItem); } }
public RandomStringGenerator(TextCase textCase) : this(BuildCharacterSet(textCase)) { }
/// <summary> /// реализовано для падежей: именительный (nominative), родительный (Genitive), винительный (accusative) /// </summary> /// <param name="_sourceNumber"></param> /// <param name="_case"></param> /// <param name="_isMale"></param> /// <param name="_firstCapital"></param> /// <returns></returns> public static string NumeralsToTxt(long _sourceNumber, TextCase _case, bool _isMale, bool _firstCapital) { string s = ""; long number = _sourceNumber; int remainder; int power = 0; if ((number >= (long)Math.Pow(10, 15)) || number < 0) { return ""; } while (number > 0) { remainder = (int)(number % 1000); number = number / 1000; switch (power) { case 12: s = MakeText(remainder, hundreds, tens, from3till19, secondMale, firstMale, trillions) + s; break; case 9: s = MakeText(remainder, hundreds, tens, from3till19, secondMale, firstMale, billions) + s; break; case 6: s = MakeText(remainder, hundreds, tens, from3till19, secondMale, firstMale, millions) + s; break; case 3: switch (_case) { case TextCase.Accusative: s = MakeText(remainder, hundreds, tens, from3till19, secondFemale, firstFemaleAccusative, thousandsAccusative) + s; break; default: s = MakeText(remainder, hundreds, tens, from3till19, secondFemale, firstFemale, thousands) + s; break; } break; default: string[] powerArray = { }; switch (_case) { case TextCase.Genitive: s = MakeText(remainder, hundredsGenetive, tensGenetive, from3till19Genetive, _isMale ? secondMaleGenetive : secondFemaleGenetive, _isMale ? firstMaleGenetive : firstFemale, powerArray) + s; break; case TextCase.Accusative: s = MakeText(remainder, hundreds, tens, from3till19, _isMale ? secondMale : secondFemale, _isMale ? firstMale : firstFemaleAccusative, powerArray) + s; break; default: s = MakeText(remainder, hundreds, tens, from3till19, _isMale ? secondMale : secondFemale, _isMale ? firstMale : firstFemale, powerArray) + s; break; } break; } power += 3; } if (_sourceNumber == 0) { s = zero + " "; } if (s != "" && _firstCapital) s = s.Substring(0, 1).ToUpper() + s.Substring(1); return s.Trim(); }
private static string Formatter(Guid value, TextCase testCase) => $"{value:N}".ToTextCase(testCase);
/// <summary> /// название м-ца /// </summary> /// <param name="_month">с единицы</param> /// <param name="_case"></param> /// <returns></returns> public static string MonthName(int _month, TextCase _case) { string s = ""; if (_month > 0 && _month <= 12) { switch (_case) { case TextCase.Genitive: s = monthNamesGenitive[_month]; break; } } return s; }
public static string ChangeCase(this string sentence, TextCase textCase) { if (textCase == TextCase.Default || textCase == TextCase.KeepOriginal) { return(sentence); } var canPrefix = !textCase.HasFlag(TextCase.NoPrefix); textCase &= ~TextCase.NoPrefix; var isProperCase = (textCase == TextCase.ProperCase); if (isProperCase) { textCase |= TextCase.Spaced; } sentence = Regex.Replace(sentence, $@"\s", " "); sentence = Regex.Replace(sentence, $@"[^\s0-9a-zA-ZÀ-ÿ{delimiters}]", " "); if (!isProperCase) { sentence = sentence.RemoveDiacritics(); } string prefix = null; string suffix = null; bool hasPrefix = false; if (canPrefix && !isProperCase) { prefix = string.Concat(sentence.TakeWhile(delimitersChars.Contains)); suffix = string.Concat(sentence.Reverse().TakeWhile(delimitersChars.Contains).Reverse()); hasPrefix = (prefix.Length > 0 || suffix.Length > 0); } var words = EnumerateWords(sentence); if (!words.Any()) { return(string.Empty); } var wordCaseMask = TextCase.UpperCase | TextCase.LowerCase | TextCase.ProperCase; var wordCase = textCase & wordCaseMask; var delimiterMask = TextCase.Hyphenated | TextCase.Underscore | TextCase.Dotted | TextCase.Spaced | TextCase.Joined; var delimiter = textCase & delimiterMask; // camel case recebe tratamento especial por este algoritmo var camelCaseMask = (int)(TextCase.CamelCase ^ TextCase.ProperCase ^ TextCase.Joined); var isCamelCase = (((int)textCase) & camelCaseMask) != 0; switch (wordCase) { case TextCase.UpperCase: words = words.Select(word => word.ToUpper()); break; case TextCase.ProperCase: words = words.Select(word => char.ToUpper(word[0]) + word.Substring(1)); break; } if (isCamelCase) { var firstWord = words.Take(1).Select(x => x.ToLower()); var otherWords = words.Skip(1); words = firstWord.Concat(otherWords); } string text = null; if (delimiter.HasFlag(TextCase.Spaced)) { text = string.Join(" ", words); } else if (delimiter.HasFlag(TextCase.Joined)) { text = string.Concat(words); } else if (delimiter.HasFlag(TextCase.Hyphenated)) { text = string.Join("-", words); } else if (delimiter.HasFlag(TextCase.Underscore)) { text = string.Join("_", words); } else if (delimiter.HasFlag(TextCase.Dotted)) { text = string.Join(".", words); } else { text = string.Concat(words); } if (hasPrefix) { if (delimiter.HasFlag(TextCase.Hyphenated)) { return('-'.Replicate(prefix.Length) + text + '-'.Replicate(suffix.Length)); } else if (delimiter.HasFlag(TextCase.Underscore)) { return('_'.Replicate(prefix.Length) + text + '_'.Replicate(suffix.Length)); } else { return(prefix + text + suffix); } } return(text); }
public static string NumeralsDoubleToTxt(double _sourceNumber, int _decimal, TextCase _case, bool _firstCapital) { long decNum = (long)Math.Round(_sourceNumber * Math.Pow(10, _decimal)) % (long)(Math.Pow(10, _decimal)); string s = String.Format(" {0} целых {1} сотых", NumeralsToTxt((long)_sourceNumber, _case, true, _firstCapital), NumeralsToTxt((long)decNum, _case, true, false)); return s.Trim(); }