コード例 #1
0
        // #############################################################################################
        // 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);
        }
コード例 #2
0
        // #############################################################################################
        // logText
        // #############################################################################################

        /** ********************************************************************************************
         *
         *  The implementation of the abstract method of parent class TextLogger. Logs messages to the
         *  application console and/or the VStudio output window.
         *
         * @param domain      The <em>Log Domain</em>.
         * @param verbosity   The verbosity. This has been checked to be active already on this
         *                    stage and is provided to be able to be logged out only.
         * @param msg         The log message
         * @param scope       Information about the scope of the <em>Log Statement</em>..
         * @param lineNumber  The line number of a multi-line message, starting with 0. For
         *                    single line messages this is -1.
         **********************************************************************************************/
        override protected void logText(Domain domain, Verbosity verbosity,
                                        AString msg,
                                        ScopeInfo scope, int lineNumber)
        {
            // loop over message, print the parts between the escape sequences
            Tokenizer msgParts = new Tokenizer(msg, '\x001B');
            Substring actual   = msgParts.Actual;
            Substring rest     = msgParts.Rest;
            int       column   = 0;

            for (;;)
            {
                msgParts.Next(Whitespaces.Keep);

                // check if this is an ANSI sequence already
                if (rest.CharAtStart() == '[')
                {
                    // read the 'm'
                    int idx = rest.IndexOf('m');

                    if (idx < 0) // unknown ANSI Code
                    {
                        ALIB.WARNING("Unknown ANSI ESC Code ");
                        textWriter.Write(actual.Buf, actual.Start, actual.Length());
                        continue;
                    }

                    column += actual.Length();

                    actual.End  = rest.Start + idx;
                    rest.Start += idx + 1;

                    textWriter.Write(actual.Buf, actual.Start, actual.Length());

                    continue;
                }
                else
                {
                    if (actual.IsNotEmpty())
                    {
                        textWriter.Write(actual.Buf, actual.Start, actual.Length());
                        column += actual.Length();
                    }
                }

                // end of loop?
                if (!msgParts.HasNext())
                {
                    break;
                }

                // found an ESC sequence
                char c = rest.Consume();

                // Colors
                bool isForeGround = true;
                if (c == 'C' || c == 'c')
                {
                    isForeGround = c == 'c';

                    c = rest.Consume();
                    int colNo = c - '0';
                    ALIB.ASSERT_WARNING(colNo >= 0 && colNo <= 9, "Unknown ESC-c code");

                    // add bg
                    colNo += isForeGround ? 0 : 10;

                    // add light
                    colNo += (isForeGround ? !IsBackgroundLight : IsBackgroundLight)  ? 20 : 0;

                    textWriter.Write(ansiCols[colNo]);
                }

                // Styles
                else if (c == 's')
                {
                    // bold/italics style not supported in Windows console

                    // reset all
                    if (rest.Consume() == 'a')
                    {
                        textWriter.Write(ANSI_RESET);
                    }
                }

                // auto tab / end of meta
                else if (c == 't' || c == 'A')
                {
                    bool endOfMeta = c == 'A';
                    c = rest.Consume();
                    int extraSpace = c >= '0' && c <= '9' ? (int)(c - '0')
                                                      : (int)(c - 'A') + 10;

                    int tabStop = AutoSizes.Next(column, extraSpace);

                    Util.WriteSpaces(textWriter, tabStop - column);
                    column = tabStop;

                    if (endOfMeta)
                    {
                        String msgPrefix;
                        switch (verbosity)
                        {
                        case lox.Verbosity.Verbose:   msgPrefix = MsgPrefixVerbose;     break;

                        case lox.Verbosity.Info:      msgPrefix = MsgPrefixInfo;        break;

                        case lox.Verbosity.Warning:   msgPrefix = MsgPrefixWarning;     break;

                        case lox.Verbosity.Error:     msgPrefix = MsgPrefixError;       break;

                        default:                  msgPrefix = "";                   break;
                        }
                        textWriter.Write(msgPrefix);
                    }
                }

                // Link (we just colorize links here)
                else if (c == 'l')
                {
                    textWriter.Write(rest.Consume() == 'S'
                                       ?  (IsBackgroundLight ? ANSI_LIGHT_BLUE : ANSI_LIGHT_BLUE)
                                       :  ANSI_STD_COL);
                }

                else
                {
                    ALIB.WARNING("Unknown ESC code");
                }
            } // write loop


            textWriter.WriteLine(MsgSuffix);
        }
コード例 #3
0
        // #############################################################################################
        // Protected interface
        // #############################################################################################

        /** ****************************************************************************************
         * Gets a node. If not existent and parameter \p create is \c true, the node is created.
         * @param   key        The key to the stored value.
         * @param   create     Flag if a non-existent entry should be created.
         * @param   separators A list of characters recognized as separators.
         * @return Returns the ourselves or a child node representing the key string.
         ******************************************************************************************/
        protected PathMap <StoreT> get(Substring key, bool create, AString separators)
        {
            int idx  = 0;
            int pLen = Path.Length();

            if (pLen > 0)
            {
                int    cmpLen = pLen < key.Length() ? pLen : key.Length();
                char[] kBuf   = key.Buf;
                char[] pBuf   = Path.Buffer();

                while (idx < cmpLen && kBuf[key.Start + idx] == pBuf[idx])
                {
                    idx++;
                }

                key.Consume(idx);
            }

            // all of 'our' path characters matched
            if (idx == pLen)
            {
                // identical to the searched string?
                if (key.IsEmpty())
                {
                    return(this);
                }

                // return matching child
                foreach (PathMap <StoreT> child in Childs)
                {
                    if (key.CharAtStart() == child.Path.CharAtStart())
                    {
                        PathMap <StoreT> search = child.get(key, create, separators);
                        if (search != null)
                        {
                            return(search);
                        }
                    }
                }

                // no child found
                if (create)
                {
                    PathMap <StoreT> newChild = null;
                    newChild = new PathMap <StoreT>(this);
                    newChild.Path._(key);
                    Childs.Add(newChild);
                    return(newChild);
                }
            }

            // nothing matched
            else if (idx == 0)
            {
                return(null);
            }


            // just a part of us matched
            else if (create)
            {
                // create new child receiving our old path (rest), our value and childs
                PathMap <StoreT> child1 = new PathMap <StoreT>(this);
                child1.Path._(Path, idx);

                List <PathMap <StoreT> > tempList = child1.Childs;
                foreach (PathMap <StoreT> child in Childs)
                {
                    child.Parent = child1;
                }
                child1.Childs = Childs;
                Childs        = tempList;

                child1.Value = Value;
                Childs.Clear();
                Childs.Add(child1);

                // cut my path and clear my value
                Path.SetLength_NC(idx);
                Value = default(StoreT);

                // create second child if remaining path is not empty
                if (key.IsNotEmpty())
                {
                    PathMap <StoreT> child2 = new PathMap <StoreT>(this);
                    child2.Path._(key);

                    Childs.Add(child2);
                    return(child2);
                }

                return(this);
            }

            // return us, or if this is not a real node, our parent
            if (Parent == null || idx == 0 || separators.IndexOf(Path.CharAt_NC(idx - 1)) >= 0)
            {
                return(this);
            }
            else
            {
                return(Parent);
            }
        }