Jump to content

User:TheFarix/AWB/scripts/FullwidthReplacer

From Wikipedia, the free encyclopedia

//Fullwidth Replacer

//

        WikiFunctions.Parse.HideText ht = new WikiFunctions.Parse.HideText(true, false, true);
        public string ProcessArticle(string ArticleText, string ArticleTitle, int wikiNamespace, out string Summary, out bool Skip)
        {
            // Adapted from User:Dinoguy1000/scripts/fullwidth2ascii.js
            Skip = false;
            Summary = "";

            ArticleText = ht.Hide(ArticleText);

            //Common punctuation
            ArticleText = ArticleText.Replace(" ", " "); //fullwidth space
            //ArticleText = ArticleText.Replace("・", "·"); //fullwidth interpunct
            ArticleText = ArticleText.Replace("。", "."); //replace ideographic period with a regular period
            //ArticleText = ArticleText.Replace("・・・", "..."); //three interpuncts normally mean an ellipsis
            //ArticleText = ArticleText.Replace("···", "..."); //catch already converted triple interpuncts - it's after the interpunct rule so we only need one go-through to catch partial replacements
            ArticleText = ArticleText.Replace("…", "..."); //it's a little ballsy, I guess, but we're already doing lots of replacements, so... (see also [[WP:ELLIPSES]])
            ArticleText = ArticleText.Replace("!", "!");
            ArticleText = ArticleText.Replace("(", "(");
            ArticleText = ArticleText.Replace(")", ")");
            ArticleText = ArticleText.Replace("?", "?");

            //Numbers
            ArticleText = ArticleText.Replace("0", "0");
            ArticleText = ArticleText.Replace("1", "1");
            ArticleText = ArticleText.Replace("2", "2");
            ArticleText = ArticleText.Replace("3", "3");
            ArticleText = ArticleText.Replace("4", "4");
            ArticleText = ArticleText.Replace("5", "5");
            ArticleText = ArticleText.Replace("6", "6");
            ArticleText = ArticleText.Replace("7", "7");
            ArticleText = ArticleText.Replace("8", "8");
            ArticleText = ArticleText.Replace("9", "9");
 
            //Latin letters, uppercase
            ArticleText = ArticleText.Replace("A", "Α");
            ArticleText = ArticleText.Replace("B", "B");
            ArticleText = ArticleText.Replace("C", "C");
            ArticleText = ArticleText.Replace("D", "D");
            ArticleText = ArticleText.Replace("E", "E");
            ArticleText = ArticleText.Replace("F", "F");
            ArticleText = ArticleText.Replace("G", "G");
            ArticleText = ArticleText.Replace("H", "H");
            ArticleText = ArticleText.Replace("I", "I");
            ArticleText = ArticleText.Replace("J", "J");
            ArticleText = ArticleText.Replace("K", "K");
            ArticleText = ArticleText.Replace("L", "L");
            ArticleText = ArticleText.Replace("M", "M");
            ArticleText = ArticleText.Replace("N", "N");
            ArticleText = ArticleText.Replace("O", "O");
            ArticleText = ArticleText.Replace("P", "P");
            ArticleText = ArticleText.Replace("Q", "Q");
            ArticleText = ArticleText.Replace("R", "R");
            ArticleText = ArticleText.Replace("S", "S");
            ArticleText = ArticleText.Replace("T", "T");
            ArticleText = ArticleText.Replace("U", "U");
            ArticleText = ArticleText.Replace("V", "V");
            ArticleText = ArticleText.Replace("W", "W");
            ArticleText = ArticleText.Replace("X", "X");
            ArticleText = ArticleText.Replace("Y", "Y");
            ArticleText = ArticleText.Replace("Z", "Z");
 
            //Latin letters, lowercase
            ArticleText = ArticleText.Replace("a", "a");
            ArticleText = ArticleText.Replace("b", "b");
            ArticleText = ArticleText.Replace("c", "c");
            ArticleText = ArticleText.Replace("d", "d");
            ArticleText = ArticleText.Replace("e", "e");
            ArticleText = ArticleText.Replace("f", "f");
            ArticleText = ArticleText.Replace("g", "g");
            ArticleText = ArticleText.Replace("h", "h");
            ArticleText = ArticleText.Replace("i", "i");
            ArticleText = ArticleText.Replace("j", "j");
            ArticleText = ArticleText.Replace("k", "k");
            ArticleText = ArticleText.Replace("l", "l");
            ArticleText = ArticleText.Replace("m", "m");
            ArticleText = ArticleText.Replace("n", "n");
            ArticleText = ArticleText.Replace("o", "o");
            ArticleText = ArticleText.Replace("p", "p");
            ArticleText = ArticleText.Replace("q", "q");
            ArticleText = ArticleText.Replace("r", "r");
            ArticleText = ArticleText.Replace("s", "s");
            ArticleText = ArticleText.Replace("t", "t");
            ArticleText = ArticleText.Replace("u", "u");
            ArticleText = ArticleText.Replace("v", "v");
            ArticleText = ArticleText.Replace("w", "w");
            ArticleText = ArticleText.Replace("x", "x");
            ArticleText = ArticleText.Replace("y", "y");
            ArticleText = ArticleText.Replace("z", "z");
 
            //Other punctuation
            ArticleText = ArticleText.Replace(""", "\"");
            ArticleText = ArticleText.Replace("#", "#");
            ArticleText = ArticleText.Replace("$", "$");
            ArticleText = ArticleText.Replace("%", "%");
            ArticleText = ArticleText.Replace("&", "&");
            ArticleText = ArticleText.Replace("'", "\'");
            ArticleText = ArticleText.Replace("*", "*");
            ArticleText = ArticleText.Replace("+", "+");
            ArticleText = ArticleText.Replace(",", ", ");
            //ArticleText = ArticleText.Replace("、", ", "); //replace ideographic comma with a regular comma
            ArticleText = ArticleText.Replace("-", "-");
            ArticleText = ArticleText.Replace(".", ". ");
            ArticleText = ArticleText.Replace("/", "/");
            ArticleText = ArticleText.Replace(":", ": ");
            ArticleText = ArticleText.Replace(";", "; ");
            ArticleText = ArticleText.Replace("<", "<");
            ArticleText = ArticleText.Replace("=", "="); //this replacement could break template usage, use {{=}} as an alternative inside templates
            ArticleText = ArticleText.Replace(">", ">");
            ArticleText = ArticleText.Replace("@", "@");
            ArticleText = ArticleText.Replace("[", "["); //this replacement could break wikimarkup usage
            ArticleText = ArticleText.Replace("\", "\\");
            ArticleText = ArticleText.Replace("]", "]"); //this replacement could break wikimarkup usage
            ArticleText = ArticleText.Replace("^", "^");
            ArticleText = ArticleText.Replace("_", "_");
            ArticleText = ArticleText.Replace("`", "`");
            ArticleText = ArticleText.Replace("{", "{"); //this replacement could break wikimarkup usage, use {{(}} as an alternative
            ArticleText = ArticleText.Replace("|", "|"); //this replacement could break template usage, use {{!}} as an alternative inside templates
            ArticleText = ArticleText.Replace("}", "}"); //this replacement could break wikimarkup usage, use {{)}} as an alternative
            ArticleText = ArticleText.Replace("~", "〜"); //ASCII tilde is, apparently, treated as a diacritic in some fonts, so this should be a better replacement
            ArticleText = ArticleText.Replace("¢", "¢");
            ArticleText = ArticleText.Replace("£", "£");
            ArticleText = ArticleText.Replace("¬", "¬");
            ArticleText = ArticleText.Replace("¦", "¦");
            ArticleText = ArticleText.Replace("¥", "¥");
            ArticleText = ArticleText.Replace("₩", "₩");
            ArticleText = ArticleText.Replace("│", "│");
            ArticleText = ArticleText.Replace("←", "←");
            ArticleText = ArticleText.Replace("↑", "↑");
            ArticleText = ArticleText.Replace("→", "→");
            ArticleText = ArticleText.Replace("↓", "↓");
            ArticleText = ArticleText.Replace("■", "■");
            ArticleText = ArticleText.Replace("○", "○");
            ArticleText = ArticleText.Replace("『", "「"); //some Japanese quote replacement
            ArticleText = ArticleText.Replace("』", "」"); //some Japanese quote replacement

            return ht.AddBack(ArticleText);

            return ArticleText;
        }
//