/*
To Translate written smileys text to smiles code
for storing in database
431267
public static function store($text)
    {
        foreach (Config::get('smiley.codes') as $key => $value) {
            $text = str_replace($key, $value, $text);
        }

        return $text;
    }
1079283
function fixUnicode(txt) {
    txt = txt.replace(/\003/g, ' ');
    txt = txt.replace(/\004/g, ' ');
    txt = txt.replace(/(\r|\n)/g, ' ');
    txt = txt.replace(/[\u007f-\uffff]/g, function (c) {
        return '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4);
    });
    return txt;
}
956083
function escapeCharacters(params) {
    return params;
    var find = new Array('.','-','%','/','\\\\',':','*','\\','<','>','|','?',' ','&','#');
    var replace = new Array('.0','.1','.2','.3','.4','.5','.6','.7','.8','.9','.a','.b','.c','.d','.e'); 
    var escaped = {};
    for (var param in params) {
        if(typeof(params[param]) == 'string') {
            escaped[param] = replaceCharacter(find, replace, params[param]);
        }
        else {
            escaped[param] = params[param];
        }
    }
    return escaped;
}
179079
function encodeEntities(value) {
  return value.
    replace(/&/g, '&amp;').
    replace(NON_ALPHANUMERIC_REGEXP, function(value){
      return '&#' + value.charCodeAt(0) + ';';
    }).
    replace(/</g, '&lt;').
    replace(/>/g, '&gt;');
}
1246217
function() {
        var updateRegex = _.bind(function () {
                // Allows checking for a nick that contains 'the_nick' or '<punctuation>the_nick<punctuation>'
                // .. where <punctuation> is any character not allowed in an IRC nick
                var regex_valid_nick_chars = 'a-z0-9_\\-{}[\\]^`|\\\\';
                var regex_nicks = Object.keys(this.nick_cache)
                    .map(_.escapeRegExp)
                    .join('|');

                this.nick_regex = new RegExp(
                    '^[^'+regex_valid_nick_chars+']?(' + regex_nicks + ')[^'+regex_valid_nick_chars+']?$', 'i'
                );
            }, this);

        function getNick (member) {
            return member.get('nick').toLowerCase();
        };

        this.nick_cache = Object.create(null);
        this.nick_regex = null;

        this.on('reset', function() {
            this.nick_cache = _.reduce(this.models, function(memo, member) {
                memo[getNick(member)] = member;
                return memo;
            }, Object.create(null));
            updateRegex();
        });

        this.on('add', function(member) {
            this.nick_cache[getNick(member)] = member;
            updateRegex();
        });

        this.on('remove', function(member) {
            delete this.nick_cache[getNick(member)];
            updateRegex();
        });

        this.on('change:nick', function(member) {
            this.nick_cache[getNick(member)] = member;
            delete this.nick_cache[member.previous('nick').toLowerCase()];
            updateRegex();
        });
    }
110672
private static boolean translate(String glob, StringBuilder result) {
        int i;
        int max;
        char c;
        int j;
        String stuff;
        int escaped;
        
        escaped = 0;
        max = glob.length();
        for (i = 0; i < max;) {
            c = glob.charAt(i++);
            if (c == '*') {
                result.append(".*");
            } else if (c == '?') {
                result.append('.');
            } else if (c == '[') {
                j = i;
                if (j < max && glob.charAt(j) == '!') {
                    j++;
                }
                if (j < max && glob.charAt(j) == ']') {
                    j++;
                }
                while (j < max && glob.charAt(j) != ']') {
                    j++;
                }
                if (j >= max) {
                    result.append("\\[");
                } else {
                    stuff = glob.substring(i, j);
                    stuff = Strings.replace(stuff, "\\", "\\\\");
                    i = j+1;
                    if (stuff.charAt(0) == '!') {
                        stuff = '^' + stuff.substring(1);
                    } else if (stuff.charAt(0) == '^') {
                        stuff = '\\' + stuff;
                    }
                    result.append('[');
                    result.append(stuff);
                    result.append(']');
                }
            } else {
            	escaped++;
                result.append(escape(c));
            }
        }
        result.append('$');
        return escaped == max;
    }
1220191
def emojificate_filter(content, autoescape=True):
    ""
    # return mark_safe(emojificate(content))
    if autoescape:
        esc = conditional_escape
    else:
        esc = lambda x: x
    return mark_safe(emojificate(esc(content)))
295320
static String sqlToRegexSimilar(
		String sqlPattern,
		char escapeChar) {
		similarEscapeRuleChecking(sqlPattern, escapeChar);

		boolean insideCharacterEnumeration = false;
		final StringBuilder javaPattern =
			new StringBuilder(sqlPattern.length() * 2);
		final int len = sqlPattern.length();
		for (int i = 0; i < len; i++) {
			char c = sqlPattern.charAt(i);
			if (c == escapeChar) {
				if (i == (len - 1)) {
					// It should never reach here after the escape rule
					// checking.
					throw invalidEscapeSequence(sqlPattern, i);
				}
				char nextChar = sqlPattern.charAt(i + 1);
				if (SQL_SIMILAR_SPECIALS.indexOf(nextChar) >= 0) {
					// special character, use \ to replace the escape char.
					if (JAVA_REGEX_SPECIALS.indexOf(nextChar) >= 0) {
						javaPattern.append('\\');
					}
					javaPattern.append(nextChar);
				} else if (nextChar == escapeChar) {
					javaPattern.append(nextChar);
				} else {
					// It should never reach here after the escape rule
					// checking.
					throw invalidEscapeSequence(sqlPattern, i);
				}
				i++; // we already process the next char.
			} else {
				switch (c) {
					case '_':
						javaPattern.append('.');
						break;
					case '%':
						javaPattern.append("(?s:.*)");
						break;
					case '[':
						javaPattern.append('[');
						insideCharacterEnumeration = true;
						i = sqlSimilarRewriteCharEnumeration(
							sqlPattern,
							javaPattern,
							i,
							escapeChar);
						break;
					case ']':
						if (!insideCharacterEnumeration) {
							throw invalidRegularExpression(sqlPattern, i);
						}
						insideCharacterEnumeration = false;
						javaPattern.append(']');
						break;
					case '\\':
						javaPattern.append("\\\\");
						break;
					case '$':

						// $ is special character in java regex, but regular in
						// SQL regex.
						javaPattern.append("\\$");
						break;
					default:
						javaPattern.append(c);
				}
			}
		}
		if (insideCharacterEnumeration) {
			throw invalidRegularExpression(sqlPattern, len);
		}

		return javaPattern.toString();
	}
961856
private static String escapeString(String s, char quote,
                          String doublequoteEscape,
                          String singlequoteEscape,
                          String backslashEscape) {
    StringBuilder sb = new StringBuilder(s.length() + 2);
    sb.append(quote);
    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      switch (c) {
        case '\n': sb.append("\\n"); break;
        case '\r': sb.append("\\r"); break;
        case '\t': sb.append("\\t"); break;
        case '\\': sb.append(backslashEscape); break;
        case '\"': sb.append(doublequoteEscape); break;
        case '\'': sb.append(singlequoteEscape); break;
        case '>':
          // Unicode-escape the '>' in '-->' and ']]>'
          if (i >= 2
              && ((s.charAt(i - 1) == '-' && s.charAt(i - 2) == '-')
                  || (s.charAt(i - 1) == ']' && s.charAt(i - 2) == ']'))) {
            sb.append("\\u003e");
          } else {
            sb.append(c);
          }
          break;
        case '<':
          // Unicode-escape the '<' in '</script' and '<!--'
          final String END_SCRIPT = "/script";
          final String START_COMMENT = "!--";

          if (s.regionMatches(true, i + 1, END_SCRIPT, 0,
                              END_SCRIPT.length())) {
            sb.append("\\u003c");
          } else if (s.regionMatches(false, i + 1, START_COMMENT, 0,
                                     START_COMMENT.length())) {
            sb.append("\\u003c");
          } else {
            sb.append(c);
          }
          break;
        default:
          // No charsetEncoder provided - pass straight Latin characters
          // through, and escape the rest.  Doing the explicit character
          // check is measurably faster than using the CharsetEncoder.
          if (c > 0x1f && c <= 0x7f) {
            sb.append(c);
          } else {
            // Other characters can be misinterpreted by some JS parsers,
            // or perhaps mangled by proxies along the way,
            // so we play it safe and Unicode escape them.
            appendHexJavaScriptRepresentation(sb, c);
          }
      }
    }
    sb.append(quote);
    return sb.toString();
  }
81170
private static String replaceLettersWithNumbersKeypad(String str, String locale) {
    if (locale.toLowerCase().startsWith("en")) {
      return str.replaceAll("[AaBbCc]", "2").replaceAll("[DdEeFf]", "3").replaceAll("[GgHhIi]", "4")
          .replaceAll("[JjKkLl]", "5").replaceAll("[MmNnOo]", "6").replaceAll("[PpQqRrSs]", "7")
          .replaceAll("[TtUuVv]", "8").replaceAll("[WwXxYyZz]", "9").replaceAll("-", "");
       }
    return str.replaceAll("-", "");
  }
696507
private String escapeSql(final Object obj) {
		if (obj == null) {
			return "";
		} else {
			String val = obj.toString();
			return val.replace("'", "''");
		}
	}
692598
static function fr_entities_encode($s)
	{
		//$s = str_replace("&", "&amp;", $s);
		$s = str_replace("é", "&eacute;", $s);
		$s = str_replace("è", "&egrave;", $s);
		$s = str_replace("ë", "&euml;", $s);
		$s = str_replace("ê", "&ecirc;", $s);
		$s = str_replace("à", "&agrave;", $s);
		$s = str_replace("ä", "&auml;", $s);
		$s = str_replace("â", "&acirc;", $s);
		$s = str_replace("ï", "&iuml;", $s);
		$s = str_replace("î", "&icirc;", $s);
		$s = str_replace("ö", "&ouml;", $s);
		$s = str_replace("ô", "&ocirc;", $s);
		$s = str_replace("ü", "&uuml;", $s);
		$s = str_replace("û", "&ucirc;", $s);
		$s = str_replace("ù", "&ugrave;", $s);
		$s = str_replace("ç", "&ccedil;", $s);
		$s = str_replace("€", "&euro;", $s);
	
		$s = str_replace("É", "&Eacute;", $s);
		$s = str_replace("È", "&Egrave;", $s);
		$s = str_replace("Ë", "&Euml;", $s);
		$s = str_replace("Ê", "&Ecirc;", $s);
		$s = str_replace("À", "&Agrave;", $s);
		$s = str_replace("Ä", "&Auml;", $s);
		$s = str_replace("Â", "&Acirc;", $s);
		$s = str_replace("Ï", "&Iuml;", $s);
		$s = str_replace("Î", "&Icirc;", $s);
		$s = str_replace("Ö", "&Ouml;", $s);
		$s = str_replace("Ô", "&Ocirc;", $s);
		$s = str_replace("Ü", "&Uuml;", $s);
		$s = str_replace("Û", "&Ucirc;", $s);
		$s = str_replace("Ù", "&Ugrave;", $s);
		$s = str_replace("Ç", "&Ccedil;", $s);
		
		return $s;
	}
1364671
function (text) {
        return text.replace(entityRegExp, function (all, numeric) {
          if (numeric) {
            if (numeric.charAt(0).toLowerCase() === 'x') {
              numeric = parseInt(numeric.substr(1), 16);
            } else {
              numeric = parseInt(numeric, 10);
            }

            // Support upper UTF
            if (numeric > 0xFFFF) {
              numeric -= 0x10000;

              return String.fromCharCode(0xD800 + (numeric >> 10), 0xDC00 + (numeric & 0x3FF));
            }

            return asciiMap[numeric] || String.fromCharCode(numeric);
          }

          return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
        });
      }
228930
private String translateWildcards(String input)
   {
      StringBuilder translated = new StringBuilder(input.length());
      boolean escaped = false;
      for (int i = 0; i < input.length(); i++)
      {
         if (input.charAt(i) == '\\')
         {
            if (escaped)
            {
               translated.append("\\\\");
               escaped = false;
            }
            else
            {
               escaped = true;
            }
         }
         else if (input.charAt(i) == '*')
         {
            if (escaped)
            {
               translated.append('*');
               escaped = false;
            }
            else
            {
               translated.append('%');
            }
         }
         else if (input.charAt(i) == '?')
         {
            if (escaped)
            {
               translated.append('?');
               escaped = false;
            }
            else
            {
               translated.append('_');
            }
         }
         else if (input.charAt(i) == '%' || input.charAt(i) == '_')
         {
            // escape every occurrence of '%' and '_'
            escaped = false;
            translated.append('\\').append(input.charAt(i));
         }
         else
         {
            if (escaped)
            {
               translated.append('\\');
               escaped = false;
            }
            translated.append(input.charAt(i));
         }
      }
      return translated.toString();
   }
587801
function( editor ) {
		editor.config.smiley_path = editor.config.smiley_path || ( this.path + 'images/' );
		editor.addCommand( 'smiley', new CKEDITOR.dialogCommand( 'smiley', {
			allowedContent: 'img[alt,height,!src,title,width]',
			requiredContent: 'img'
		} ) );
		editor.ui.addButton && editor.ui.addButton( 'Smiley', {
			label: editor.lang.smiley.toolbar,
			command: 'smiley',
			toolbar: 'insert,50'
		} );
		CKEDITOR.dialog.add( 'smiley', this.path + 'dialogs/smiley.js' );
	}
1038332
function (text, languageCode, id) {
        var payload = textHelper.encodePayload(text, languageCode);
        if (!id) { id = []; }

        return ndef.record(ndef.TNF_WELL_KNOWN, ndef.RTD_TEXT, id, payload);
    }
190499
function UTF8ArrToStr (aBytes) {

  var sView = "";

  for (var nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++) {
    nPart = aBytes[nIdx];
    sView += String.fromCharCode(
      nPart > 251 && nPart < 254 && nIdx + 5 < nLen ? /* six bytes */
        /* (nPart - 252 << 32) is not possible in ECMAScript! So...: */
        (nPart - 252) * 1073741824 + (aBytes[++nIdx] - 128 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
      : nPart > 247 && nPart < 252 && nIdx + 4 < nLen ? /* five bytes */
        (nPart - 248 << 24) + (aBytes[++nIdx] - 128 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
      : nPart > 239 && nPart < 248 && nIdx + 3 < nLen ? /* four bytes */
        (nPart - 240 << 18) + (aBytes[++nIdx] - 128 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
      : nPart > 223 && nPart < 240 && nIdx + 2 < nLen ? /* three bytes */
        (nPart - 224 << 12) + (aBytes[++nIdx] - 128 << 6) + aBytes[++nIdx] - 128
      : nPart > 191 && nPart < 224 && nIdx + 1 < nLen ? /* two bytes */
        (nPart - 192 << 6) + aBytes[++nIdx] - 128
      : /* nPart < 127 ? */ /* one byte */
        nPart
    );
  }

  return sView;

}