Exemplo n.º 1
0
        /// <summary>
        /// Log the information as plain text
        /// </summary>
        /// <param name="Info">The text/information that should be logged</param>
        protected void LogPlain(ktString Info)
        {
            if (!m_Enabled) { return; }

            if (ktDebug.WrapLevel > 0)
            {
                if ( OnDebug != null )
                {
                    OnDebug(Info);
                }
                Info.Prepend(ktDebug.GetPrefix());
                /*				Info.Replace( "\n", "<ktDebug::Wrap::n>", true );
                                Info.Replace( "<ktDebug::Wrap::n>", "\n" + Prefix, true );*/
            }

            Console.WriteLine(Info);
        }
Exemplo n.º 2
0
        public ktString AsXML(bool IncludeDeclaration, ktString Prefix)
        {
            // Define the variable to store the xml-structure
            ktString XML = new ktString();

            // Should we include the XML-declaration
            if (IncludeDeclaration)
            {
                // Do so...
                XML = Prefix + "<?xml version=\"" + m_Version + "\" encoding=\"" + m_Encoding + "\"?>\n";
            }

            // Define...
            ktString StartElm = "", EndElm = "", Content = "", Name = "";
            bool First = true;

            // If the list has info...
            if (m_Node != null)
            {
                // Add beginning
                StartElm = Prefix + "<";
                EndElm = "</";

                Name.SetValue(m_Node.Name);
                Name.Trim();

                // No name??
                if (Name.IsEmpty())
                {
                    StartElm += "NN";
                    EndElm += "NN";
                    // Yippie, name...
                }
                else
                {
                    // Add name
                    StartElm += Name;
                    EndElm += Name;
                }

                // Add end...
                StartElm += ">";
                EndElm += ">";

                // If the list has a value
                if (m_Node.Value != null)
                {
                    // Special, just for blocks...
                    if (m_Node.Value.GetType() == typeof(ktBlock))
                    {
                        ktList L = ((ktBlock)m_Node.Value).Lines;
                        if (L != null)
                        {
                            // Get it...
                            Content = ktXML.FromList(L).AsXML(IncludeDeclaration, m_Prefix + Prefix);
                        }
                    }
                    else if ((m_Node.Value.GetType() == typeof(ktToken)) &&
                              (((ktToken)m_Node.Value).Type == ktTokenType.Block))
                    {
                        if (((ktToken)m_Node.Value).Block == null)
                        {
                            goto EndOfNode;
                        }
                        ktList L = ((ktToken)m_Node.Value).Block.Lines;
                        if (L != null)
                        {
                            // Get it...
                            Content = ktXML.FromList(L).AsXML(IncludeDeclaration, m_Prefix + Prefix);
                        }
                    }
                    else
                    {
                        // Get it...
                        Content = m_Node.Value.ToString();
                    }
                }
                // No node info...
            }
            else
            {
                // Use default...
                StartElm = Prefix + "<POST>";
                EndElm = "</POST>";
            }

            EndOfNode:

            // Little "hack" if it,s the "first level"
            if (Prefix.IsEmpty())
            {
                First = false;
            }

            // Go thrugh the child nodes
            foreach (ktXML N in this)
            {
                // If it's the first
                if (First)
                {
                    // If content isn't empty
                    if (!Content.IsEmpty())
                    {
                        // Add approiate prefixes...
                        Content = Prefix + m_Prefix + Content + "\n"/* + Prefix*/;
                    }
                    // No more first...
                    First = false;
                }

                // Get the childs xml-structure (extended prefix and no XML-decl.)
                Content += N.AsXML(false, Prefix + m_Prefix) + "\n";
            }

            // Remove trialing newlines
            Content.Trim(ktStripType.trailing, "\n");

            // If the "content"/structure contains newlines or elements
            if ((!Content.IsEmpty()) && (Content.Contains("\n") || Content.Contains("<")))
            {
                // Add newline after start-element
                StartElm = StartElm + "\n";

                // hum... Add newline if the content doesn't end with one!?
                if ((!Content.StartsWith("\n")) && (Content.Last() != '\n'))
                {
                    Prefix.Prepend("\n");
                }

                // Add Prefix before end-element and a newline after..
                EndElm = Prefix + EndElm + "\n";
            }

            // Put together start content/childs and end element...
            XML += StartElm + Content + EndElm;

            // Done.. Return the structure
            return XML;// + Get_R();
        }
Exemplo n.º 3
0
        // Set the pattern to use
        public bool SetPattern(ktString Pattern)
        {
            RegexOptions Opt = new RegexOptions();

            switch (m_Mode)
            {
                case ktRE_Mode.PERL:
                    {
                        ktString OPattern = new ktString(Pattern);
                        char Delim = Pattern.First();
                        Pattern.RemoveFirst();

                        int Pos = Find(Pattern, @"[^\\]" + Delim.ToString());
                        if (Pos < 0)
                        {
                            throw new ktError("ktRegEx::SetPattern() : The pattern isn't Perl compatible (" + OPattern + ")", ktERR.NOTFOUND);
                        }
                        else
                        {
                            Pos++;
                        }

                        ktString Modifiers = Pattern.SubStr(Pos + 1);
                        Pattern.Remove((uint)Pos);

                        for (uint I = 0; I < Modifiers.Len(); I++)
                        {
                            //						Console.Write( Modifiers[I].ToString() + ";" );
                            switch (Modifiers[I])
                            {
                                case 'i':
                                    {
                                        Opt = Opt | RegexOptions.IgnoreCase;
                                        break;
                                    }
                                case 'm':
                                    {
                                        Opt = Opt | RegexOptions.Multiline;
                                        break;
                                    }
                                case 'x':
                                    {
                                        Opt = Opt | RegexOptions.IgnorePatternWhitespace;
                                        break;
                                    }
                                case 'A':
                                    {
                                        if (Pattern.First() != '^')
                                        {
                                            Pattern.Prepend("^");
                                        }
                                        break;
                                    }/*
                            case 'i': {
                                Opt = Opt | RegexOptions.IgnoreCase;
                                break;
                             }*/
                            }
                        }

                        break;
                    }
                case ktRE_Mode.Plain:
                    {
                        break;
                    }
                default:
                    {
                        throw new ktError("ktRegExp::SetPattern(): The mode '" + GetModeAsString() +
                                "' is not implementet yet!",
                            ktERR.NOTIMP);
                    }
            }

            // Set the pattern
            m_Pattern = Pattern;

            // Take care of the (if any) exception
            try
            {
                // Create the (internal) regex object
                m_P = new Regex(m_Pattern.GetValue(), Opt);
            }
            catch (ktError Ex)
            {
                SetError("Couldn't set pattern and create a new (internal) Regex object" +
                         Ex.Message, ktERR.REGEX_COULDNT_SET_PATTERN);
                return false;
            }
            catch (Exception Ex)
            {
                SetError("Couldn't set pattern and create a new (internal) Regex object" +
                         Ex.Message, ktERR.REGEX_COULDNT_SET_PATTERN);
                return false;
            }

            return true;
        }