/// <summary> /// Parsese the key/value text and then validates the key against the /// token lookup. /// Also sets the key based on the settings of the token if valid. /// </summary> /// <param name="text"></param> /// <param name="delimeter"></param> /// <returns></returns> protected override KeyValueData <string, string> InternalParseLine(string text, string delimeter, bool applySettings) { KeyValueData <string, string> pair = base.InternalParseLine(text, delimeter, false); // Only massage the key and validate it if there is a key. if (string.IsNullOrEmpty(pair.Key)) { return(pair); } string key = pair.Key; // Convert to lowercase if token lookup is not case sensitive. // Trim white space if it's not important. if (!_tokenLookup.IsCaseSensitive && _settings.ConvertKeysToLowerCase) { key = key.ToLower(); } if (!_tokenLookup.IsWhiteSpaceSensitive && _settings.TrimWhiteSpaceFromKeys) { key = key.Trim(); } bool isValid = _tokenLookup.IsValid(key); // Set the new key, and whether it's valid. pair.SetIsValidKey(isValid); // Only set the new key if valid. pair.SetKey(key); return(pair); }
protected virtual KeyValueData <string, string> InternalParseLine(string text, string delimeter, bool applySettings) { // Check for emtpy string if (string.IsNullOrEmpty(text)) { return(KeyValueData <string, string> .Empty); } // Now check to see if there is no delmiter or at the beggining. int ndxKeyValueSeparator = text.IndexOf(delimeter); if (ndxKeyValueSeparator <= 0) { return(new KeyValueData <string, string>(string.Empty, text, true)); } string key = text.Substring(0, ndxKeyValueSeparator); string value = text.Substring(ndxKeyValueSeparator + 1); KeyValueData <string, string> pair = new KeyValueData <string, string>(key, value, true); if (applySettings) { if (_settings.ConvertKeysToLowerCase) { key = key.ToLower(); } if (_settings.TrimWhiteSpaceFromKeys) { key = key.Trim(); } pair.SetKey(key); } return(pair); }