예제 #1
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 04JAN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Convert \\uxxxx to it's string format
         * @param source string to Convert.
         * @return result string.
         */
        public static string ConvertUTF8(string source)
        {
            StringBuilder result2 = new StringBuilder();
            StringGetter input = new StringGetter(source);

            try
            {
                int c = input.Read();

                while (c != -1) // Convert until EOF
                {
                    string text;
                    if (c == '\\')
                    {
                        c = input.Read();
                        switch ((char)c)
                        {
                            case 'u':
                                text = "";
                                for (int i = 0; i < 4; i++)
                                {
                                    text += ((char)input.Read()).ToString();
                                }
                                text = int.Parse(text, NumberStyles.HexNumber).ToString();
                                break;
                            case 'x':
                                text = "";
                                for (int i = 0; i < 2; i++)
                                {
                                    text += ((char)input.Read());
                                }
                                text = int.Parse(text, NumberStyles.HexNumber).ToString();
                                break;
                            default:
                                text = "\\" + (char)c;
                                break;

                        }

                    }
                    else
                    {
                        text = "" + (char)c;
                    }

                    StringBuilder s = result2;
                    s.Append(text);

                    c = input.Read();
                }
            }
            catch
            {
                input.Close();

            }

            return result2.ToString().Trim();
        }
예제 #2
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 04JAN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Convert \\uxxxx to it's string format
         * @param source string to Convert.
         * @return result string.
         */
        public static string ConvertUTF8(string source)
        {
            StringBuilder result2 = new StringBuilder();
            StringGetter  input   = new StringGetter(source);

            try
            {
                int c = input.Read();

                while (c != -1) // Convert until EOF
                {
                    string text;
                    if (c == '\\')
                    {
                        c = input.Read();
                        switch ((char)c)
                        {
                        case 'u':
                            text = "";
                            for (int i = 0; i < 4; i++)
                            {
                                text += ((char)input.Read()).ToString();
                            }
                            text = int.Parse(text, NumberStyles.HexNumber).ToString();
                            break;

                        case 'x':
                            text = "";
                            for (int i = 0; i < 2; i++)
                            {
                                text += ((char)input.Read());
                            }
                            text = int.Parse(text, NumberStyles.HexNumber).ToString();
                            break;

                        default:
                            text = "\\" + (char)c;
                            break;
                        }
                    }
                    else
                    {
                        text = "" + (char)c;
                    }

                    StringBuilder s = result2;
                    s.Append(text);

                    c = input.Read();
                }
            }
            catch
            {
                input.Close();
            }


            return(result2.ToString().Trim());
        }
예제 #3
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 04JAN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Remove double "\\" and change to one "\"
         * @param source the string need to change
         * @return the result string.
         */
        public static string RemoveDoubleBackSlash(string source)
        {
            StringBuilder result2 = new StringBuilder();
            StringGetter  input   = new StringGetter(source);

            try
            {
                int c = input.Read();

                while (c != -1) // Convert until EOF
                {
                    string text;
                    if (c == '\\')
                    {
                        c = input.Read();
                        if (c == '\\')
                        {
                            text = "\\";
                        }
                        else
                        {
                            text = "\\" + (char)c;
                        }
                    }
                    else
                    {
                        text = "" + (char)c;
                    }

                    StringBuilder s = result2;
                    s.Append(text);

                    c = input.Read();
                }
            }
            catch
            {
                input.Close();
            }


            return(result2.ToString().Trim());
        }
예제 #4
0
        //[------------------------------ PUBLIC METHODS --------------------------]
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 04JAN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Convert html to plain text
         * @param source HTML string.
         * @return plain text.
         */
        public string Convert(string source)
        {
            StringBuilder result = new StringBuilder();
            StringBuilder result2 = new StringBuilder();
            StringGetter input = new StringGetter(source);

            try
            {
                int c = input.Read();

                while (c != -1) // Convert until EOF
                {
                    string text;
                    if (c == '<') // It's a tag!!
                    {
                        string currentTag = GetTag(input); // Get the rest of the tag
                        text = ConvertTag(currentTag);
                    }
                    else if (c == '&')
                    {
                        string specialchar = GetSpecial(input);
                        if (specialchar.Equals("lt;") || specialchar.Equals("#60"))
                        {
                            text = "<";
                        }
                        else if (specialchar.Equals("gt;") || specialchar.Equals("#62"))
                        {
                            text = ">";
                        }
                        else if (specialchar.Equals("amp;") || specialchar.Equals("#38"))
                        {
                            text = "&";
                        }
                        else if (specialchar.Equals("nbsp;"))
                        {
                            text = " ";
                        }
                        else if (specialchar.Equals("quot;") || specialchar.Equals("#34"))
                        {
                            text = "\"";
                        }
                        else if (specialchar.Equals("copy;") || specialchar.Equals("#169"))
                        {
                            text = "[Copyright]";
                        }
                        else if (specialchar.Equals("reg;") || specialchar.Equals("#174"))
                        {
                            text = "[Registered]";
                        }
                        else if (specialchar.Equals("trade;") || specialchar.Equals("#153"))
                        {
                            text = "[Trademark]";
                        }
                        else
                        {
                            text = "&" + specialchar;
                        }
                    }
                    else if (!_pre && IsWhitespace((char)c))
                    {
                        StringBuilder s = _inBody ? result : result2;
                        if (s.Length > 0 && IsWhitespace(s[s.Length - 1]))
                        {
                            text = "";
                        }
                        else
                        {
                            text = " ";
                        }
                    }
                    else
                    {
                        text = "" + (char)c;
                    }

                    StringBuilder s2 = _inBody ? result : result2;
                    s2.Append(text);

                    c = input.Read();
                }
            }
            catch
            {
                input.Close();

            }

            StringBuilder s1 = _bodyFound ? result : result2;
            return s1.ToString().Trim();
        }
예제 #5
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 04JAN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Remove double "\\" and change to one "\"
         * @param source the string need to change
         * @return the result string.
         */
        public static string RemoveDoubleBackSlash(string source)
        {
            StringBuilder result2 = new StringBuilder();
            StringGetter input = new StringGetter(source);

            try
            {
                int c = input.Read();

                while (c != -1) // Convert until EOF
                {
                    string text;
                    if (c == '\\')
                    {
                        c = input.Read();
                        if (c == '\\')
                        {
                            text = "\\";
                        }
                        else
                        {
                            text = "\\" + (char)c;
                        }

                    }
                    else
                    {
                        text = "" + (char)c;
                    }

                    StringBuilder s = result2;
                    s.Append(text);

                    c = input.Read();
                }
            }
            catch
            {
                input.Close();

            }

            return result2.ToString().Trim();
        }
예제 #6
0
        //[------------------------------ PUBLIC METHODS --------------------------]
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 04JAN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Convert html to plain text
         * @param source HTML string.
         * @return plain text.
         */
        public string Convert(string source)
        {
            StringBuilder result  = new StringBuilder();
            StringBuilder result2 = new StringBuilder();
            StringGetter  input   = new StringGetter(source);

            try
            {
                int c = input.Read();

                while (c != -1) // Convert until EOF
                {
                    string text;
                    if (c == '<')                          // It's a tag!!
                    {
                        string currentTag = GetTag(input); // Get the rest of the tag
                        text = ConvertTag(currentTag);
                    }
                    else if (c == '&')
                    {
                        string specialchar = GetSpecial(input);
                        if (specialchar.Equals("lt;") || specialchar.Equals("#60"))
                        {
                            text = "<";
                        }
                        else if (specialchar.Equals("gt;") || specialchar.Equals("#62"))
                        {
                            text = ">";
                        }
                        else if (specialchar.Equals("amp;") || specialchar.Equals("#38"))
                        {
                            text = "&";
                        }
                        else if (specialchar.Equals("nbsp;"))
                        {
                            text = " ";
                        }
                        else if (specialchar.Equals("quot;") || specialchar.Equals("#34"))
                        {
                            text = "\"";
                        }
                        else if (specialchar.Equals("copy;") || specialchar.Equals("#169"))
                        {
                            text = "[Copyright]";
                        }
                        else if (specialchar.Equals("reg;") || specialchar.Equals("#174"))
                        {
                            text = "[Registered]";
                        }
                        else if (specialchar.Equals("trade;") || specialchar.Equals("#153"))
                        {
                            text = "[Trademark]";
                        }
                        else
                        {
                            text = "&" + specialchar;
                        }
                    }
                    else if (!_pre && IsWhitespace((char)c))
                    {
                        StringBuilder s = _inBody ? result : result2;
                        if (s.Length > 0 && IsWhitespace(s[s.Length - 1]))
                        {
                            text = "";
                        }
                        else
                        {
                            text = " ";
                        }
                    }
                    else
                    {
                        text = "" + (char)c;
                    }

                    StringBuilder s2 = _inBody ? result : result2;
                    s2.Append(text);

                    c = input.Read();
                }
            }
            catch
            {
                input.Close();
            }

            StringBuilder s1 = _bodyFound ? result : result2;

            return(s1.ToString().Trim());
        }