Sanitize input and trim first word if Gherkin lang
975327
function trim(str) {
  var input = str.replace(/\s\s+/g, ' ').trim();

  var words = input.split(' ');
  if (_.contains(LANG_WORDS, _.first(words))) {
    return words.slice(1).join(' ');
  }
  return input;
}
846438
def sanitizeString(name):
    """"""
    newString = name
    # string cleaning, pass 1
    replaceTable = [
        ('^', '^5e'),  # we need to do this one first
        ('"', '^22'),
        ('<', '^3c'),
        ('?', '^3f'),
        ('*', '^2a'),
        ('=', '^3d'),
        ('+', '^2b'),
        ('>', '^3e'),
        ('|', '^7c'),
        (',', '^2c'),
    ]

    #   "   hex 22           <   hex 3c           ?   hex 3f
    #   *   hex 2a           =   hex 3d           ^   hex 5e
    #   +   hex 2b           >   hex 3e           |   hex 7c
    #   ,   hex 2c

    for r in replaceTable:
        newString = newString.replace(r[0], r[1])
    # replace ascii 0-32
    for x in range(0, 33):
        # must add somewhat arbitrary num to avoid conflict at deSanitization
        # conflict example: is ^x1e supposed to be ^x1 (ascii 1) followed by
        # letter 'e' or really ^x1e (ascii 30)
        newString = newString.replace(
            chr(x), hex(x + sanitizerNum).replace('0x', '^'))

    replaceTable2 = [
        ("/", "="),
        (":", "+"),
        (".", ","),
    ]

    # / -> =
    # : -> +
    # . -> ,

    # string cleaning pass 2
    for r in replaceTable2:
        newString = newString.replace(r[0], r[1])
    return newString
466337
def clean_text(text):
    """"""
    # Replace a few nasty unicode characters with their ASCII equivalent
    maps = {u'×': u'x', u'–': u'-', u'−': '-'}
    for element in maps:
        text = text.replace(element, maps[element])

    # Replace genitives
    text = re.sub(r'(?<=\w)\'s\b|(?<=\w)s\'(?!\w)', '  ', text)

    logging.debug(u'Clean text: "%s"', text)

    return text
449858
def clean_description desc
      strip_stopwords(
        desc.gsub(XML_TAG_FILTER,' ')
            .gsub(EMAIL_FILTER,'')
            .gsub(URL_FILTER,'')
            .gsub(GENDER_FILTER,'')
            .gsub(NEW_LINES,'')
            .gsub(SYMBOL_FILTER,' ')
            .gsub(WHITESPACE,' ')
            .gsub(WORDS_IN_BRACKETS, '\1')
            .gsub(CODE_TOKEN_FILTER,'')
            .downcase
            .strip
        )
    end
1291654
def sanitize_string(string_or_unicode):
    
    if isinstance(string_or_unicode, unicode):
        return string_or_unicode.strip()
    elif isinstance(string_or_unicode, str):
        return string_or_unicode.decode('utf-8').strip()
    else:  # e.g. if input is None
        return u''
1009394
function sanitize (val) {
  if (typeof val !== 'string') {
    return '';
  }
  val = val.replace(/\n/g,'\n');
  val = val.replace(/"/g,'""');
  return val ;
}
804698
def replace_first(input, string, replacement = ''.freeze)
      input.to_s.sub(string.to_s, replacement.to_s)
    end
1036607
public static String sanitize(final String input, final boolean lax) {
		return sanitize(input, lax ? LAX_POLICY : STRICT_POLICY);
	}
1069096
function (decorator, txt) {
        var decostr = "@" + decorator;
        var r = txt
            .replace(decostr, "")
            .trim()
            ;
        if (debug) console.log(`Cleaning deco: ${decorator} in  ${txt}
        Result: ${r}
        `);


        return r;
    }
386590
function sanitize(arr, opts) {
  return _.reduce(arr, function (acc, keywords) {
    keywords = keywords.split(' ').filter(Boolean);
    return acc.concat(keywords).map(function (keyword, i) {
      if (opts && opts.sanitize) {
        return opts.sanitize(keyword, i, keywords);
      }
      return keyword.toLowerCase();
    }).sort();
  }, []);
}
1066545
def _sanitize(self, unsanitized):
        

        sanitized = ""

        # strip punctuation and diacritics
        replace_punct = str.maketrans( string.punctuation + "᾽᾿῾", ' '*(len(string.punctuation) + 3)  )
        sanitized = unsanitized.translate( replace_punct )
        sanitized = "".join(c for c in unicodedata.normalize("NFD", sanitized) if unicodedata.category(c) != "Mn")

        #finally, lose all whitespace
        sanitized = re.sub(r'\s+','', sanitized)

        return sanitized
992031
def clean(ctx, text):
    
    text = conversions.to_string(text, ctx)
    return ''.join([c for c in text if ord(c) >= 32])
881394
def clean_var(text):
    """"""
    text = re_invalid_var.sub('', text)
    text = re_invalid_start.sub('', text)
    return text
213106
def clean(inputline, strip=True, rem_indents=True, encoding_errors="replace"):
    """"""
    stdout_encoding = get_encoding(sys.stdout)
    inputline = str(inputline)
    if rem_indents:
        inputline = inputline.replace(openindent, "").replace(closeindent, "")
    if strip:
        inputline = inputline.strip()
    return inputline.encode(stdout_encoding, encoding_errors).decode(stdout_encoding)
346602
def sanitize_word(word):
    
    # use an unicode string for `unidecode`
    if type(word) == str:
        try:
            word = word.decode()
        except AttributeError:
            pass  # Python3

    # remove trailing spaces
    word = word.strip()

    # remove stuff between parentheses
    word = re.sub(r'\([^)]*\)', '', word)

    # remove accents, hyphens & other special chars
    word = re.sub(r'[ "\'-;.]+', '', unidecode(word))

    # only lowercase
    return word.lower()
1238456
private String sanitizePrincipal(final String input) {
        String s = "";

        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);

            if (c == '*') {
                // escape asterisk
                s += "\\2a";
            } else if (c == '(') {
                // escape left parenthesis
                s += "\\28";
            } else if (c == ')') {
                // escape right parenthesis
                s += "\\29";
            } else if (c == '\\') {
                // escape backslash
                s += "\\5c";
            } else if (c == '\u0000') {
                // escape NULL char
                s += "\\00";
            } else if (c <= 0x7f) {
                // regular 1-byte UTF-8 char
                s += String.valueOf(c);
            } else if (c >= 0x080) {
                // higher-order 2, 3 and 4-byte UTF-8 chars
                byte[] utf8bytes = String.valueOf(c).getBytes(StandardCharsets.UTF_8);

                for (byte b : utf8bytes) {
                    s += String.format(Locale.ENGLISH, "\\%02x", b);
                }
            }
        }

        return s;
    }
732830
def _sanitizeFilename(filename):
    """"""
    global _sanitize_trans
    out = filename.translate(_sanitize_trans)
    # leading dot becomes "_"
    if out and out[0] == '.':
        out = out[1:]
    return out