Collation helpers
346934
function compareValue(aVal, bVal) {
  var cmp, i, collate;
  if (isString(aVal) && isString(bVal)) {
    collate = _arrayOptions('sortCollate');
    return collate(aVal, bVal);
  } else if (isArray(aVal) && isArray(bVal)) {
    if (aVal.length < bVal.length) {
      return -1;
    } else if (aVal.length > bVal.length) {
      return 1;
    } else {
      for(i = 0; i < aVal.length; i++) {
        cmp = compareValue(aVal[i], bVal[i]);
        if (cmp !== 0) {
          return cmp;
        }
      }
      return 0;
    }
  }
  return aVal < bVal ? -1 : aVal > bVal ? 1 : 0;
}
373895
protected function getCollatedSuggestion($collation = '')
    {
        if (is_string($collation)) {
            return $collation;
        }
        if (is_object($collation)) {
            if (isset($collation->misspellingsAndCorrections)) {
                foreach ($collation->misspellingsAndCorrections as $key => $value) {
                    return $value;
                }
            }
        }
        return '';
    }
263117
def normalizer(text, exclusion=OPERATIONS_EXCLUSION, lower=True, separate_char='-', **kwargs):
    
    clean_str = re.sub(r'[^\w{}]'.format(
        "".join(exclusion)), separate_char, text.strip()) or ''
    clean_lowerbar = clean_str_without_accents = strip_accents(clean_str)

    if '_' not in exclusion:
        clean_lowerbar = re.sub(r'\_', separate_char, clean_str_without_accents.strip())

    limit_guion = re.sub(r'\-+', separate_char, clean_lowerbar.strip())

    # TODO: refactor with a regexp
    if limit_guion and separate_char and separate_char in limit_guion[0]:
        limit_guion = limit_guion[1:]

    if limit_guion and separate_char and separate_char in limit_guion[-1]:
        limit_guion = limit_guion[:-1]

    if lower:
        limit_guion = limit_guion.lower()

    return limit_guion
1317975
function filterTranslate (translateList, words) {
  if (translateList && translateList.length === 1 && translateList[0].trans === words) {
    return []
  }

  return translateList
}
1330937
def _build_abbreviation_regex(input_string):
        
        result=''
        for char in input_string:
            result += '[%s%s]?' % (char.upper(), char.lower())
        return '(%s)' % result
330889
function (cols, term, opts) {
            opts = opts || {};
            return format("MATCH %s AGAINST (%s%s)", this.literal(toArray(cols)),
                this.literal(toArray(term).join(" ")), opts.boolean ? " IN BOOLEAN MODE" : "");
        }
1050282
function normalize(word) {
        var result = '';
        for (var i = 0; i < word.length; i++) {
            var kana = word[i];
            var target = transform[kana];
            if (target === false) {
                continue;
            }
            if (target) {
                kana = target;
            }
            result += kana;
        }
        return result;
    }
42846
def collate_fonts_data(fonts_data):
    """"""
    glyphs = {}

    for family in fonts_data:
        for glyph in family:
            if glyph['unicode'] not in glyphs:
                glyphs[glyph['unicode']] = glyph
            else:
                c = glyphs[glyph['unicode']]['contours']
                glyphs[glyph['unicode']]['contours'] = c | glyph['contours']
    return glyphs.values()
560121
protected function getNiceSuggestion($collation = '')
    {
        $collationParts = explode(' ', $collation);

        // Remove advanced query params from the beginning of each collation part.
        foreach ($collationParts as $key => &$part) {
            $part = ltrim($part, '+');
        }

        return implode(' ', $collationParts);
    }
261692
def add_delete(self, selector, limit, collation=None):
        
        cmd = SON([('q', selector), ('limit', limit)])
        collation = validate_collation_or_none(collation)
        if collation is not None:
            self.uses_collation = True
            cmd['collation'] = collation
        self.ops.append((_DELETE, cmd))
1134982
function collationIndex(x) {
  var id = ['boolean', 'number', 'string', 'object'];
  var idx = id.indexOf(typeof x);
  //false if -1 otherwise true, but fast!!!!1
  if (~idx) {
    if (x === null) {
      return 1;
    }
    if (Array.isArray(x)) {
      return 5;
    }
    return idx < 3 ? (idx + 2) : (idx + 3);
  }
  if (Array.isArray(x)) {
    return 5;
  }
}
834925
def upcaseTokens(s,l,t):
    """"""
    return [ tt.upper() for tt in map(_ustr,t) ]
1214938
def _slugify(text, delim=u'-'):
    """"""
    result = []
    for word in _punct_re.split(text.lower()):
        word = word.encode('utf-8')
        if word:
            result.append(word)
    slugified = delim.join([i.decode('utf-8') for i in result])
    return re.sub('[^a-zA-Z0-9\\s\\-]{1}', replace_char, slugified).lower()
256292
private function fieldWithCollation(string $field, string $collation): Expression
    {
        return DB::raw($field . ' /*! COLLATE ' . $collation . ' */');
    }
701151
function hyphenReplace ($0,
  from, fM, fm, fp, fpr, fb,
  to, tM, tm, tp, tpr, tb) {
  if (isX(fM)) {
    from = '';
  } else if (isX(fm)) {
    from = '>=' + fM + '.0.0';
  } else if (isX(fp)) {
    from = '>=' + fM + '.' + fm + '.0';
  } else {
    from = '>=' + from;
  }

  if (isX(tM)) {
    to = '';
  } else if (isX(tm)) {
    to = '<' + (+tM + 1) + '.0.0';
  } else if (isX(tp)) {
    to = '<' + tM + '.' + (+tm + 1) + '.0';
  } else if (tpr) {
    to = '<=' + tM + '.' + tm + '.' + tp + '-' + tpr;
  } else {
    to = '<=' + to;
  }

  return (from + ' ' + to).trim()
}
723356
def latinize(mapping, bind, values):
    
    for v in values:
        if isinstance(v, six.string_types):
            v = transliterate(v)
        yield v
483042
def downcaseTokens(s,l,t):
    """"""
    return [ tt.lower() for tt in map(_ustr,t) ]