/** **************************************************************************************** * Helper method used when reading file. * @param subs A sub-string. * @return true if provided substring starts with comment character. ******************************************************************************************/ protected bool startsWithCommentSymbol(Substring subs) { int i = commentChars.IndexOf(subs.CharAtStart()); return((i >= 0 && i < 2) || (i == 2 && subs.CharAt(1) == '/')); }
/** **************************************************************************************** * Interprets given \p src as a verbosity. * A case insensitive comparison of only the first (!) character of the start of the string * is performed (against 'v', 'i', 'w' and 'e'). * If no match is found, \e %Verbosity::Off is returned. * @param src The string to 'parse'. * @returns The verbosity read. ******************************************************************************************/ public static Verbosity ReadVerbosity(Substring src) { int idx = src.IndexOfAny(CString.DefaultWhitespaces, Inclusion.Exclude); if (idx >= 0) { char c = Char.ToLower(src.CharAt(idx)); if (c == 'v') { return(Verbosity.Verbose); } if (c == 'i') { return(Verbosity.Info); } if (c == 'w') { return(Verbosity.Warning); } if (c == 'e') { return(Verbosity.Error); } } return(Verbosity.Off); }
/** **************************************************************************************** * Interprets given \p src as a boolean value. * \ref cs::aworx::lib::enums::Inclusion "enums.Inclusion". * If the case insensitive comparison of the first non-whitespace characters of the string with * with values "t", "1", "y", "on", "ok" * matches, \c true is returned. * Otherwise, including the case that \p src is 'nulled', \c false is returned. * * @param src The string to 'parse'. * * @returns The \b %Case value read. ******************************************************************************************/ public static bool ReadBoolean(Substring src) { int idx = src.IndexOfAny(CString.DefaultWhitespaces, Inclusion.Exclude); if (idx >= 0) { char c = Char.ToLower(src.CharAt(idx)); foreach (char v in trueValuesBoolean) { if (c == v) { return(true); } } char c2 = Char.ToLower(src.CharAt(idx + 1)); if (c == 'o' && (c2 == 'n' || c2 == 'k')) { return(true); } } return(false); }
/** **************************************************************************************** * Interprets given \p src as a value of enum type * \ref cs::aworx::lib::enums::Inclusion "enums.Inclusion". * If the case insensitive comparison of the first non-whitespace characters of the string * with values "i", "y", "t", "1" * matches, \b %Inclusion.Include is returned. * Otherwise, including the case that \p src is 'nulled', \b %Inclusion.Exclude is returned. * * @param src The string to 'parse'. * * @returns The \b %Inclusion value read. ******************************************************************************************/ public static Inclusion ReadInclusion(Substring src) { int idx = src.IndexOfAny(CString.DefaultWhitespaces, Inclusion.Exclude); if (idx >= 0) { int c = Char.ToLower(src.CharAt(idx)); foreach (char v in trueValuesInclusion) { if (c == v) { return(Inclusion.Include); } } } return(Inclusion.Exclude); }
/** **************************************************************************************** * Interprets given \p src as a value of enum type * \ref aworx.lib::enums::Case "enums.Case". * If the case insensitive comparison of the first non-whitespace characters of the string * with values "s", "y", "t", "1" * matches, \b %Case.Sensitive is returned. * Otherwise, including the case that \p src is 'nulled', \b %Case.Ignore is returned. * * @param src The string to 'parse'. * * @returns The \b %Case value read. ******************************************************************************************/ public static Case ReadCase(Substring src) { int idx = src.IndexOfAny(CString.DefaultWhitespaces, Inclusion.Exclude); if (idx >= 0) { int c = Char.ToLower(src.CharAt(idx)); foreach (char v in trueValuesCase) { if (c == v) { return(Case.Sensitive); } } } return(Case.Ignore); }
// ############################################################################################# // Internals // ############################################################################################# /** **************************************************************************************** * Internal, recursive helper of #Find. * * @param domainPath Path to search. * @param sensitivity Denotes if domain name search is treated case sensitive or not. * @param maxCreate The maximum number of sub domains that are created if not * found at the end of the path. * @param[out] wasCreated Output parameter that is set \c true if domain was not found * and hence created. * @return The domain found or created. ******************************************************************************************/ protected Domain findRecursive(Substring domainPath, Case sensitivity, int maxCreate, ref bool wasCreated) { //--- get act sub-name and rest of path domainPath.Consume(PathSeparator); int endSubName = domainPath.IndexOf(PathSeparator); ALIB.ASSERT_ERROR(endSubName != 0, "Internal Error"); // find end of actual domain name and save rest Substring restOfDomainPath = tSubstring2; restOfDomainPath.SetNull(); if (endSubName > 0) { domainPath.Split(endSubName, restOfDomainPath, 1); } // search sub-domain Domain subDomain = null; // "." if (domainPath.Equals(".")) { subDomain = this; } // ".." else if (domainPath.Equals("..")) { subDomain = Parent != null ? Parent : this; } // search in sub-domain else { int i; bool fixedOnce = false; for (;;) { for (i = 0; i < SubDomains.Count; i++) { int comparison = SubDomains[i].Name.CompareTo(domainPath, sensitivity); if (comparison >= 0) { if (comparison == 0) { subDomain = SubDomains[i]; } break; } } // domain found? if (subDomain != null) { break; } // try and fix name if (!fixedOnce) { fixedOnce = true; bool illegalCharacterFound = false; for (int cp = 0; cp < domainPath.Length(); ++cp) { char c = domainPath.CharAt(cp); if (c < '-' || c > 'z' || c == '<' || c == '>' || c == '[' || c == ']' || c == '=' || c == '?' || c == ';' || c == ':' || c == '\\' || c == '\'' || c == '.' || c == ',' ) { illegalCharacterFound = true; domainPath.Buf[domainPath.Start + cp] = '#'; } } if (illegalCharacterFound) { continue; } } // create if (maxCreate == 0) { return(null); } wasCreated = true; SubDomains.Insert(i, subDomain = new Domain(this, new AString(domainPath))); maxCreate--; if (maxCreate == 0) { return(subDomain); } break; } } // recursion? if (restOfDomainPath.IsNotEmpty()) { domainPath.Set(restOfDomainPath); return(subDomain.findRecursive(domainPath, sensitivity, maxCreate, ref wasCreated)); } // that's it return(subDomain); }
public void FrontEnd() { // empty substring { Substring subs = new Substring(); UT_EQ('\0', subs.CharAtStart( )); UT_EQ('\0', subs.CharAt(0)); UT_EQ('\0', subs.CharAt(1)); UT_EQ('\0', subs.CharAt(-1)); UT_EQ('\0', subs.CharAt(2)); UT_EQ('\0', subs.CharAt(-2)); UT_EQ('\0', subs.CharAtEnd( )); UT_EQ('\0', subs.CharAtEnd(0)); UT_EQ('\0', subs.CharAtEnd(1)); UT_EQ('\0', subs.CharAtEnd(-1)); UT_EQ('\0', subs.CharAtEnd(2)); UT_EQ('\0', subs.CharAtEnd(-2)); } // empty substring { Substring subs = new Substring("aaaaaaaaaaaa"); subs.Start = 5; subs.End = 4; UT_EQ('\0', subs.CharAtStart( )); UT_EQ('\0', subs.CharAt(0)); UT_EQ('\0', subs.CharAt(1)); UT_EQ('\0', subs.CharAt(-1)); UT_EQ('\0', subs.CharAt(2)); UT_EQ('\0', subs.CharAt(-2)); UT_EQ('\0', subs.CharAtEnd( )); UT_EQ('\0', subs.CharAtEnd(0)); UT_EQ('\0', subs.CharAtEnd(1)); UT_EQ('\0', subs.CharAtEnd(-1)); UT_EQ('\0', subs.CharAtEnd(2)); UT_EQ('\0', subs.CharAtEnd(-2)); } // substring of length 1 { Substring subs = new Substring("aaaaaaaaaaaa"); subs.Start = subs.End = 5; UT_EQ('a', subs.CharAtStart( )); UT_EQ('a', subs.CharAt(0)); UT_EQ('\0', subs.CharAt(1)); UT_EQ('\0', subs.CharAt(-1)); UT_EQ('\0', subs.CharAt(2)); UT_EQ('\0', subs.CharAt(-2)); UT_EQ('a', subs.CharAtEnd( )); UT_EQ('a', subs.CharAtEnd(0)); UT_EQ('\0', subs.CharAtEnd(1)); UT_EQ('\0', subs.CharAtEnd(-1)); UT_EQ('\0', subs.CharAtEnd(2)); UT_EQ('\0', subs.CharAtEnd(-2)); } // substring of length 2 { Substring subs = new Substring("aaaaabbbbbb"); subs.End = subs.IndexOf('b'); subs.Start = subs.End - 1; UT_EQ('a', subs.CharAtStart( )); UT_EQ('a', subs.CharAt(0)); UT_EQ('b', subs.CharAt(1)); UT_EQ('\0', subs.CharAt(-1)); UT_EQ('\0', subs.CharAt(2)); UT_EQ('\0', subs.CharAt(-2)); UT_EQ('b', subs.CharAtEnd( )); UT_EQ('b', subs.CharAtEnd(0)); UT_EQ('a', subs.CharAtEnd(1)); UT_EQ('\0', subs.CharAtEnd(-1)); UT_EQ('\0', subs.CharAtEnd(2)); UT_EQ('\0', subs.CharAtEnd(-2)); } }