Convert a string in TOML format into a GSIM instance

    >>> gsim('[BooreAtkinson2011]')
    [BooreAtkinson2011]
965498
def gsim(value):
    
    if not value.startswith('['):  # assume the GSIM name
        value = '[%s]' % value
    [(gsim_name, kwargs)] = toml.loads(value).items()
    minimum_distance = float(kwargs.pop('minimum_distance', 0))
    if gsim_name == 'FromFile':
        return FromFile()
    try:
        gsim_class = registry[gsim_name]
    except KeyError:
        raise ValueError('Unknown GSIM: %s' % gsim_name)
    gs = gsim_class(**kwargs)
    gs._toml = '\n'.join(line.strip() for line in value.splitlines())
    gs.minimum_distance = minimum_distance
    return gs
790599
function toSingleRule(str) {

  return str
    // replace modulus with shortcuts
    .replace(/([nivwft]) % (\d+)/g, '$1$2')
    // replace ranges
    .replace(/([nivwft]\d*) (=|\!=) (\d+[.,][.,\d]+)/g, function (match, v, cond, range) {
      // range = 5,8,9 (simple set)
      if (range.indexOf('..') < 0 && range.indexOf(',') >= 0) {
        if (cond === '=') {
          return format('IN([ %s ], %s)', range.split(',').join(', '), v);
        }
        return format('!IN([ %s ], %s)', range.split(',').join(', '), v);
      }
      // range = 0..5 or 0..5,8..20 or 0..5,8
      var conditions = range.split(',').map(function (interval) {
        // simple value
        if (interval.indexOf('..') < 0) {
          return format('%s %s %s', v, cond, interval);
        }
        // range
        var start = interval.split('..')[0],
            end   = interval.split('..')[1];
        if (cond === '=') {
          return format('B(%s, %s, %s)', start, end, v);
        }
        return format('!B(%s, %s, %s)', start, end, v);
      });

      var joined;
      if (conditions.length > 1) {
        joined =  '(' + conditions.join(cond === '=' ? ' || ' : ' && ') + ')';
      } else {
        joined = conditions[0];
      }
      return joined;
    })
    .replace(/ = /g, ' === ')
    .replace(/ != /g, ' !== ')
    .replace(/ or /g, ' || ')
    .replace(/ and /g, ' && ');
}
289828
function ( value ) {
		var tmp;

		if ( value === null || value === undefined ) {
			return undefined;
		}
		else if ( value === "true" ) {
			return true;
		}
		else if ( value === "false" ) {
			return false;
		}
		else if ( value === "null" ) {
			return null;
		}
		else if ( value === "undefined" ) {
			return undefined;
		}
		else if ( value === "" ) {
			return value;
		}
		else if ( !isNaN( tmp = Number( value ) ) ) {
			return tmp;
		}
		else if ( regex.json_wrap.test( value ) ) {
			return json.decode( value, true ) || value;
		}
		else {
			return value;
		}
	}
764092
def parse_utuple(s,urx,length=2):
    ''''''
    if type(urx) != str:
        urx=urx.pattern;
    if length is not None and length < 1:
        raise ValueError("invalid length: {}".format(length));
    if length == 1:
        rx = r"^ *\( *{urx} *,? *\) *$".format(urx=urx);
    elif length is None:
        rx = r"^ *\( *(?:{urx} *, *)*{urx} *,? *\) *$".format(urx=urx);
    else:
        rx = r"^ *\( *(?:{urx} *, *){{{rep1}}}{urx} *,? *\) *$".format(
            rep1=length-1,
            urx=urx);
    return re.match(rx,s);
170450
def parse_version_string(version_string):
    """"""
    string_parts =  version_string.split(".")
    version_parts = [
        int(re.match("([0-9]*)", string_parts[0]).group(0)),
        int(re.match("([0-9]*)", string_parts[1]).group(0)),
        int(re.match("([0-9]*)", string_parts[2]).group(0))
    ]
    return version_parts
1150767
def convert(value):
  
  s0 = "Sbp" + value if value in COLLISIONS else value
  s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', s0)
  return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() + "_t"
646886
def to_s( pattern="" )
      return '' if self.empty?
      to_return = pattern.is_a?( Symbol ) ? @@patterns[pattern] : pattern
      to_return = @@patterns[:us_short] if to_return.empty?
      @pattern_map.each { |pat, replacement| to_return = to_return.gsub( pat, replacement ) }
      to_return.strip
    end
352369
function parse_BrtFmt(data, length) {
	var ifmt = data.read_shift(2);
	var stFmtCode = parse_XLWideString(data,length-2);
	return [ifmt, stFmtCode];
}
1063130
function(str){
        var versionArray = str.split(",");//replace with regex
        return {
            "raw":str,
            "major":parseInt(versionArray[0].split(" ")[1], 10),
            "minor":parseInt(versionArray[1], 10),
            "revision":parseInt(versionArray[2], 10),
            "revisionStr":versionArray[2]
        };
    }
1081913
function toMs (value) {
  if (!['number', 'string'].includes(typeof value)) {
    return 0
  }

  const num = +value
  if (!isNaN(num)) {
    return num
  }

  let msNum

  try {
    msNum = ms(value)
  } catch (error) {
    msNum = 0
  }

  if (typeof msNum === 'number') {
    return msNum
  }

  return 0
}
585088
def _get_col_dimstr(tdim, is_string=False):
    
    dimstr = ''
    if tdim is None:
        dimstr = 'array[bad TDIM]'
    else:
        if is_string:
            if len(tdim) > 1:
                dimstr = [str(d) for d in tdim[1:]]
        else:
            if len(tdim) > 1 or tdim[0] > 1:
                dimstr = [str(d) for d in tdim]
        if dimstr != '':
            dimstr = ','.join(dimstr)
            dimstr = 'array[%s]' % dimstr

    return dimstr
338851
def time_from_hhmmssmmm(string, decimal_separator="."):
    
    if decimal_separator == ",":
        pattern = HHMMSS_MMM_PATTERN_COMMA
    else:
        pattern = HHMMSS_MMM_PATTERN
    v_length = TimeValue("0.000")
    try:
        match = pattern.search(string)
        if match is not None:
            v_h = int(match.group(1))
            v_m = int(match.group(2))
            v_s = int(match.group(3))
            v_f = TimeValue("0." + match.group(4))
            v_length = v_h * 3600 + v_m * 60 + v_s + v_f
    except:
        pass
    return v_length
1271156
function convert(key, value) {
  key = camel(key);
  if (is.string(value)) return key + '_str';
  if (isInt(value)) return key + '_int';
  if (isFloat(value)) return key + '_real';
  if (is.date(value)) return key + '_date';
  if (is.boolean(value)) return key + '_bool';
}
371342
def get_gsims(self, trt):
        
        if trt == '*' or trt == b'*':  # fake logictree
            [trt] = self.values
        return sorted(self.values[trt])
273581
def parse_with_toml(data):
    """"""
    try:
        return toml.loads("key={}".format(data), DynaBox).key
    except toml.TomlDecodeError:
        return data
289069
function saslprep(input, opts = {}) {
  if (typeof input !== 'string') {
    throw new TypeError('Expected string.');
  }

  if (input.length === 0) {
    return '';
  }

  // 1. Map
  const mapped_input = toCodePoints(input)
    // 1.1 mapping to space
    .map(character => (mapping2space.get(character) ? 0x20 : character))
    // 1.2 mapping to nothing
    .filter(character => !mapping2nothing.get(character));

  // 2. Normalize
  const normalized_input = String.fromCodePoint
    .apply(null, mapped_input)
    .normalize('NFKC');

  const normalized_map = toCodePoints(normalized_input);

  // 3. Prohibit
  const hasProhibited = normalized_map.some(character =>
    prohibited_characters.get(character)
  );

  if (hasProhibited) {
    throw new Error(
      'Prohibited character, see https://tools.ietf.org/html/rfc4013#section-2.3'
    );
  }

  // Unassigned Code Points
  if (opts.allowUnassigned !== true) {
    const hasUnassigned = normalized_map.some(character =>
      unassigned_code_points.get(character)
    );

    if (hasUnassigned) {
      throw new Error(
        'Unassigned code point, see https://tools.ietf.org/html/rfc4013#section-2.5'
      );
    }
  }

  // 4. check bidi

  const hasBidiRAL = normalized_map.some(character =>
    bidirectional_r_al.get(character)
  );

  const hasBidiL = normalized_map.some(character =>
    bidirectional_l.get(character)
  );

  // 4.1 If a string contains any RandALCat character, the string MUST NOT
  // contain any LCat character.
  if (hasBidiRAL && hasBidiL) {
    throw new Error(
      'String must not contain RandALCat and LCat at the same time,' +
        ' see https://tools.ietf.org/html/rfc3454#section-6'
    );
  }

  /**
   * 4.2 If a string contains any RandALCat character, a RandALCat
   * character MUST be the first character of the string, and a
   * RandALCat character MUST be the last character of the string.
   */

  const isFirstBidiRAL = bidirectional_r_al.get(
    getCodePoint(first(normalized_input))
  );
  const isLastBidiRAL = bidirectional_r_al.get(
    getCodePoint(last(normalized_input))
  );

  if (hasBidiRAL && !(isFirstBidiRAL && isLastBidiRAL)) {
    throw new Error(
      'Bidirectional RandALCat character must be the first and the last' +
        ' character of the string, see https://tools.ietf.org/html/rfc3454#section-6'
    );
  }

  return normalized_input;
}
1158448
function(s) {
    try {
        const re = new RegExp(s);
        return re.source;
    } catch (ex) {
        normalizeRegexSource.message = ex.toString();
    }
    return '';
}