/* Key-value pairs are delimited by a single space in a given line.
The key and value in the key-value pair are separated by a colon `:`
Example line: `process_name:foo group_name:bar pid:123`
359425
function splitData(raw) {
	var lines = raw.split( "\n" );
	var line = lines[0];
	var vals = {};
	line.split(" ").forEach(function(kvp){
		var data = kvp.split(":");
		vals[data[0]] = data[1];
	});
	if ( lines.length > 1 ) {
		lines.splice( 0 , 1 );
		vals.body = lines;
	}
	return vals;
}
1073792
function determineKeyValueSpaces(obj, tabSize) {

  let lastDepth = 0;
  let spacesIndex = 0;

  let spaces = [];

    //iterate over all lines
  obj.forEach((line) => {

    if (lastDepth !== line.depth) {
      spacesIndex++;
    }

    //key found
    if (line.key) {

      //value found
      if (line.value) {

        //block line found
        if (line.isBlockLine) {
          line.keyValueSpaces = ' ';
        } else {

          if (!spaces[spacesIndex]) {
            spaces[spacesIndex] = {
              maxKeyLength: 1
            };
          }

          //determine maxKeyLength
          if (spaces[spacesIndex].maxKeyLength < line.key.length) {
            if (spaces[spacesIndex].maxKeyLength < line.key.length) {
              spaces[spacesIndex].maxKeyLength = line.key.length;
            }
          }
        }
      }
    }

    lastDepth = line.depth;
  });

  // reset the counters
  lastDepth = 0;
  spacesIndex = 0;

  //iterate over all lines
  obj.forEach((line) => {
    
    if (lastDepth !== line.depth) {
      spacesIndex++;
    }

    //key found
    if (line.key) {

      //value found
      if (line.value) {

        //block line found
        if (!line.isBlockLine) {
          if(spaces[spacesIndex]){
            let numSpaces = spaces[spacesIndex].maxKeyLength - line.key.length + tabSize;
            line.keyValueSpaces = '';
            for (let i = 0; i < numSpaces; i++) {
              line.keyValueSpaces += ' ';
            }
          }
        }
      }
    }

    lastDepth = line.depth;

  });

  console.log(obj);

  return obj;
}
303529
def _format_pair_with_equals(explode, separator, escape, key, value):
    
    if not value:
        return key + '='
    return _format_pair(explode, separator, escape, key, value)
434697
function keysFromPath(path) {
    // from http://codereview.stackexchange.com/a/63010/8176
    /**
     * Repeatedly capture either:
     * - a bracketed expression, discarding optional matching quotes inside, or
     * - an unbracketed expression, delimited by a dot or a bracket.
     */
    var re = /\[("|')(.+)\1\]|([^.\[\]]+)/g;

    var elements = [];
    var result;
    while ((result = re.exec(path)) !== null) {
      elements.push(result[2] || result[3]);
    }
    return elements;
  }
608433
def process_data(lines)  
      data = {}
      lines.each do |line|
        line = line.split
        key = line.first.split('.value').first
        data[key] = line.last
      end
      data
    end
361763
private static String getEntryNameForMap(String property, Boolean key, Integer index) {
        return String.format("%s.%d.%s", property, index, key ? "key" : "value");
    }
362665
protected function parseEnvLine($line, &$key, &$value)
    {
        $parseOk = false;

        $keyExpr = '/(^\S+)\s*=\s*/';
        if (preg_match($keyExpr, $line, $matched) === 1) {
            $key = $matched[1];
            $value = substr($line, strlen($matched[0]));
            $parseOk = true;
        }

        return $parseOk;
    }
986576
function parseQueryStringItemValue(key, value) {
  if (Array.isArray(value)) {
    // deduplicate and simplify arrays
    value = value.filter((v, idx) => value.indexOf(v) === idx);
    if (value.length === 1) value = value[0];
  } else if (value.indexOf(':') > 0) {
    value = value.split(',').reduce((result, pair) => {
      const parts = pair.split(':');
      result[parts[0]] = parseQueryStringItemValue(key, parts[1]);
      return result;
    }, {});
  } else if (value.indexOf(',') > 0) {
    value = value.split(',').map(v => {
      return parseQueryStringItemValue(key, v);
    });
  } else if (value.toLowerCase() === 'true' || value.toLowerCase() === 'false') {
    value = value.toLowerCase() === 'true';
  } else if (!Number.isNaN(value) && !STRING_OPTIONS.has(key)) {
    const numericValue = parseFloat(value);
    if (!Number.isNaN(numericValue)) {
      value = parseFloat(value);
    }
  }

  return value;
}
1336319
function(value) {
      var s = '';
      var i = 1;
      var len = value.length - 1;
      var c, c2, hex, n, index, length;

      while (i < len) {
        c = value.charAt(i++);

        if (c === '\\') {
          if (i < len) {
            c2 = value.charCodeAt(i);
            if (isLineTerminator(c2)) {
              i++;
              if (c2 === 0x0D && i < len && value.charCodeAt(i) === 0x0A) {
                i++;
              }
              continue;
            }
          }

          c = value.charAt(i++);
          switch (c) {
            case 'b':
              c = '\b';
              break;
            case 't':
              c = '\t';
              break;
            case 'r':
              c = '\r';
              break;
            case 'n':
              c = '\n';
              break;
            case 'v':
              c = '\x0B';
              break;
            case 'f':
              c = '\f';
              break;
            case 'u':
            case 'x':
              if (c === 'u' && i < len && value.charAt(i) === '{') {
                i++;
                index = value.indexOf('}', i);
                if (!~index) {
                  this.unexpected();
                }
                hex = value.substring(i, index);
                i = index + 1;
              } else {
                length = c === 'u' ? 4 : 2;
                hex = value.substr(i, length);
                i += length;
              }
              c = fromCodePoint(parseInt(hex, 16));
              break;
            default:
              if (isOctalDigit(c)) {
                n = c;
                do {
                  c = value.charAt(i);
                  if (!isOctalDigit(c)) {
                    break;
                  }
                  n += c;
                } while (i++ < len && n.length < 3);

                if (n.length > 0 && n.charAt(0) === '0') {
                  n = n.substring(1);
                }
                c = fromCharCode(parseInt(n, 8));
              }
          }
        }
        s += c;
      }

      return s;
    }
18058
def comma_separated_pairs(value):
    """"""
    pairs = value.split(",")
    results = {}
    for pair in pairs:
        key, pair_value = pair.split('=')
        results[key] = pair_value
    return results
743529
private String excludeKey(String name, String cmpname, String value) {
        StringBuilder sb = new StringBuilder(cmpname == null ? "" : cmpname + ".");
        sb.append(name).append(value == null ? "" : "=" + value);
        return sb.toString();
    }
1050668
public void parse(String s) {
        Preconditions.checkNotNull(s, "s");
        if (s.length() == 0) {
            // Nothing to do.
            return;
        }

        val pairs = s.split(pairDelimiter);
        for (String pair : pairs) {
            int delimiterPos = pair.indexOf(keyValueDelimiter);
            if (delimiterPos < 0) {
                throw new IllegalArgumentException(String.format("Invalid pair '%s' (missing key-value delimiter).", pair));
            }

            String key = pair.substring(0, delimiterPos);
            String value;
            if (delimiterPos == pair.length() - 1) {
                value = "";
            } else {
                value = pair.substring(delimiterPos + 1);
            }

            Extractor<?> e = this.extractors.get(key);
            Preconditions.checkArgument(e != null, String.format("No extractor provided for key '%s'.", key));
            e.process(value);
        }
    }
657934
def []=(key, value)
      key = key.to_s

      if has_key?(key)
        @lines[ @indicies[key] ] = value
      else
        @lines << value
        @indicies[key] = @lines.length - 1
      end
    end
384858
def set_delimiter(self, delimiter):
        
        for key in self.keys():
            if delimiter in key:
                raise ValueError('Key {!r} collides with delimiter {!r}', key,
                                 delimiter)
        self._delimiter = delimiter
        for key in self._values.keys():
            if isinstance(self._values[key], FlatDict):
                self._values[key].set_delimiter(delimiter)
1193681
function pair(name, value, i) {
  if(typeof name === 'function') return name(value);
  if(!name) return {name: `notMappedField${i}`, value};

  var candidateKey = name.split('|');
  var directive = candidateKey[1];
  if(keys.indexOf(directive) !== -1) return {name: candidateKey[0], value: format[directive](value)};

  return {name, value};
}
353988
def extract_pair(line)
      key, value = line.split("=", 2)
      [key.tr("-", "_").to_sym, value.gsub(/[\n\r]+/, "")]
    end
166653
function parseHeaders(headers) {
  var parsed = {}, key, val, i;

  if (!headers) return parsed;

  forEach(headers.split('\n'), function(line) {
    i = line.indexOf(':');
    key = lowercase(trim(line.substr(0, i)));
    val = trim(line.substr(i + 1));

    if (key) {
      if (parsed[key]) {
        parsed[key] += ', ' + val;
      } else {
        parsed[key] = val;
      }
    }
  });

  return parsed;
}