public static string AsReadable(this string value, ReadablilityCondition normalizeConditions = ReadablilityCondition.Default) { if (value.IsNullEmptyOrWhiteSpace()) { return(value); } if (normalizeConditions == 0) { normalizeConditions = ReadablilityCondition.Default; } string workingValue = value; // Validate Whitespace Trim Conditions if (normalizeConditions.TrimStartWhitespace()) { workingValue = workingValue.TrimStart(); } if (normalizeConditions.TrimEndWhitespace()) { workingValue = workingValue.TrimEnd(); } // Validate Normalization Conditions if (!normalizeConditions.CanMakeReadable(workingValue)) { return(workingValue); } // Declarations StringBuilder returnValue = new StringBuilder(); IEnumerable <string> workingValues = workingValue.SeperateForReadability(normalizeConditions); IEnumerator <string> iterator = workingValues.GetEnumerator(); bool hasValue = iterator.MoveNext(); bool isFirst = true; while (hasValue) { returnValue.Append(isFirst ? normalizeConditions.Capitalize(iterator.Current) : iterator.Current); hasValue = iterator.MoveNext(); isFirst = false; if (hasValue) { returnValue.Append(WhiteSpace); } } return(returnValue.ToString()); }
private static string Capitalize(this ReadablilityCondition conditions, string value) { if (conditions.Capitalize() && !value.IsNullEmptyOrWhiteSpace()) { char firstChar = value[0]; string substring = value.Length == 0 ? string.Empty : value.Substring(1); if (Char.IsLower(firstChar)) { return(string.Format("{0}{1}", Char.ToUpper(firstChar), substring)); } } return(value); }
private static void Capitalize(this ReadablilityCondition conditions, ref string value) { value = conditions.Capitalize(value); }
public static string AsReadable(this string value, ReadablilityCondition normalizeConditions = ReadablilityCondition.Default) { if (value.IsNullEmptyOrWhiteSpace()) return value; if (normalizeConditions == 0) normalizeConditions = ReadablilityCondition.Default; string workingValue = value; // Validate Whitespace Trim Conditions if (normalizeConditions.TrimStartWhitespace()) workingValue = workingValue.TrimStart(); if (normalizeConditions.TrimEndWhitespace()) workingValue = workingValue.TrimEnd(); // Validate Normalization Conditions if (!normalizeConditions.CanMakeReadable(workingValue)) return workingValue; // Declarations StringBuilder returnValue = new StringBuilder(); IEnumerable<string> workingValues = workingValue.SeperateForReadability(normalizeConditions); IEnumerator<string> iterator = workingValues.GetEnumerator(); bool hasValue = iterator.MoveNext(); bool isFirst = true; while (hasValue) { returnValue.Append(isFirst ? normalizeConditions.Capitalize(iterator.Current) : iterator.Current); hasValue = iterator.MoveNext(); isFirst = false; if (hasValue) returnValue.Append(WhiteSpace); } return returnValue.ToString(); }