Parses header lines

            Header example:
            Date    2012/11/15    User    anonymous
            Time    06:07:08PM    Software version: 4.0

            Example laboratory
            Arizona
432688
def parse_headerline(self, line):
        
        if line.startswith('Date'):
            splitted = self.splitLine(line)
            if len(splitted) > 1:
                self._header['Date'] = splitted[1]
                if len(splitted) > 2 and splitted[2] == 'User':
                    self._header['Date'] = splitted[1]
                    self._header['User'] = splitted[3] \
                        if len(splitted) > 3 else ''
                else:
                    self.warn("Unexpected header format", numline=self._numline)
            else:
                self.warn("Unexpected header format", numline=self._numline)

            return 0

        if line.startswith('Time'):
            splitted = self.splitLine(line)
            if len(splitted) > 1:
                self._header['Time'] = splitted[1]
            else:
                self.warn("Unexpected header format", numline=self._numline)

            return 0

        if line.startswith('Sample/ctrl'):
            # Sample/ctrl ID    Pat/Ctr/cAl    Test name    Test type
            if len(self._header) == 0:
                self.warn("No header found", numline=self._numline)
                return -1

            #Grab column names
            self._end_header = True
            self._columns = self.splitLine(line)
            return 1
174446
function headersToString(headers){
  var lines = [];
  for(var name in headers){
    lines.push(name + ': ' + headers[name]);
  }
  return lines.join('\n');
}
218187
private void parseHeaderLine(Map<String, String> headers, String header) {
        final int colonOffset = header.indexOf(':');
        if (colonOffset == -1) {
            // This header line is malformed, skip it.
            return;
        }
        String headerName = header.substring(0, colonOffset).trim().toLowerCase();
        String headerValue = header.substring(header.indexOf(':') + 1).trim();
        if (getHeader(headers, headerName) != null) {
            // More that one heder of that name exists,
            // append to the list.
            headers.put(headerName, getHeader(headers, headerName) + ',' + headerValue);
        } else {
            headers.put(headerName, headerValue);
        }
    }
994760
private static void _parseHeaderLine (@Nonnull final FileItemHeaders aHeaders, @Nonnull final String sHeader)
  {
    final int nColonOffset = sHeader.indexOf (':');
    if (nColonOffset == -1)
    {
      // This header line is malformed, skip it.
      if (LOGGER.isWarnEnabled ())
        LOGGER.warn ("Found malformed HTTP header line '" + sHeader + "'");
      return;
    }
    final String sHeaderName = sHeader.substring (0, nColonOffset).trim ();
    final String sHeaderValue = sHeader.substring (sHeader.indexOf (':') + 1).trim ();
    aHeaders.addHeader (sHeaderName, sHeaderValue);
  }
1056953
function parseHeaders(headerString) {
	var headers = {};
	var headersArray = headerString.split(/[\r\n]+/);
	headersArray.forEach(function (headerString) {
		var headerChunks = headerString.split(':');
		headers[headerChunks.shift().trim()] = headerChunks.join(':').trim();
	});
	return headers;
}
330069
function parseUsersLinux(lines, phase) {
  let result = [];
  let result_who = [];
  let result_w = {};
  let w_first = true;
  let w_header = [];
  let w_pos = [];
  let who_line = {};

  let is_whopart = true;
  lines.forEach(function (line) {
    if (line === '---') {
      is_whopart = false;
    } else {
      let l = line.replace(/ +/g, ' ').split(' ');

      // who part
      if (is_whopart) {
        result_who.push({
          user: l[0],
          tty: l[1],
          date: l[2],
          time: l[3],
          ip: (l && l.length > 4) ? l[4].replace(/\(/g, '').replace(/\)/g, '') : ''
        });
      } else {
        // w part
        if (w_first) {    // header
          w_header = l;
          w_header.forEach(function (item) {
            w_pos.push(line.indexOf(item));
          });
          w_first = false;
        } else {
          // split by w_pos
          result_w.user = line.substring(w_pos[0], w_pos[1] - 1).trim();
          result_w.tty = line.substring(w_pos[1], w_pos[2] - 1).trim();
          result_w.ip = line.substring(w_pos[2], w_pos[3] - 1).replace(/\(/g, '').replace(/\)/g, '').trim();
          result_w.command = line.substring(w_pos[7], 1000).trim();
          // find corresponding 'who' line
          who_line = result_who.filter(function (obj) {
            return (obj.user.substring(0, 8).trim() === result_w.user && obj.tty === result_w.tty);
          });
          if (who_line.length === 1) {
            result.push({
              user: who_line[0].user,
              tty: who_line[0].tty,
              date: who_line[0].date,
              time: who_line[0].time,
              ip: who_line[0].ip,
              command: result_w.command
            });
          }
        }
      }
    }
  });
  if (result.length === 0 && phase === 2) {
    return result_who;
  } else {
    return result;
  }
}
1315452
def parse_headers(
            self,
            lines: List[bytes]
    ) -> Tuple['CIMultiDictProxy[str]',
               RawHeaders,
               Optional[bool],
               Optional[str],
               bool,
               bool]:
        
        headers, raw_headers = self._headers_parser.parse_headers(lines)
        close_conn = None
        encoding = None
        upgrade = False
        chunked = False

        # keep-alive
        conn = headers.get(hdrs.CONNECTION)
        if conn:
            v = conn.lower()
            if v == 'close':
                close_conn = True
            elif v == 'keep-alive':
                close_conn = False
            elif v == 'upgrade':
                upgrade = True

        # encoding
        enc = headers.get(hdrs.CONTENT_ENCODING)
        if enc:
            enc = enc.lower()
            if enc in ('gzip', 'deflate', 'br'):
                encoding = enc

        # chunking
        te = headers.get(hdrs.TRANSFER_ENCODING)
        if te and 'chunked' in te.lower():
            chunked = True

        return (headers, raw_headers, close_conn, encoding, upgrade, chunked)
76353
def parse(s):
    """"""
    stopwatch = StopWatch()
    for line in s.splitlines():
      if line.strip():
        parts = line.split(None)
        name = parts[0]
        if name != "%":  # ie not the header line
          rest = (float(v) for v in parts[2:])
          stopwatch.times[parts[0]].merge(Stat.build(*rest))
    return stopwatch
1050712
private function parseDate()
    {
        $todayDateTime = strtotime(date('Y-m-d H:00:00'));
        if($todayDateTime !== $this->currentFileDateTime)
        {
            $this->getNewDateFileName($todayDateTime);
        }
    }
1368039
def getTime(self):
    
    headers = self._headers
    timeStringIndex = headers.index(TIMESTAMP_FIELD)
    timeString = self.peek()[timeStringIndex]
    return  datetime.strptime(timeString, "%Y/%m/%d %H:%M:%S")
30315
function(line) {
    header.resolveTempo();
    multilineVars.is_in_header = false;	// We should have gotten a key header by now, but just in case, this is definitely out of the header.
    var i = 0;
    var startOfLine = multilineVars.iChar;
    //multilineVars.havent_set_length = false;	// To late to set this now.
    // see if there is nothing but a comment on this line. If so, just ignore it. A full line comment is optional white space followed by %
    while (tokenizer.isWhiteSpace(line.charAt(i)) && i < line.length) {
      i++;
    }
    if (i === line.length || line.charAt(i) === '%') {
      return;

    }
    // Start with the standard staff, clef and key symbols on each line
    var delayStartNewLine = multilineVars.start_new_line;
    if (multilineVars.continueall === undefined)
      multilineVars.start_new_line = true;
    else
      multilineVars.start_new_line = false;
    var tripletNotesLeft = 0;

    // See if the line starts with a header field
    var retHeader = header.letter_to_body_header(line, i);
    if (retHeader[0] > 0) {
      i += retHeader[0];
      // TODO-PER: Handle inline headers
    }
    var el = { };

    while (i < line.length)
    {
      var startI = i;
      if (line.charAt(i) === '%')
        break;

      var retInlineHeader = header.letter_to_inline_header(line, i);
      if (retInlineHeader[0] > 0) {
        i += retInlineHeader[0];
        // TODO-PER: Handle inline headers
        //multilineVars.start_new_line = false;
      } else {
        // Wait until here to actually start the line because we know we're past the inline statements.
        if (delayStartNewLine) {
          startNewLine();
          delayStartNewLine = false;
        }

        // We need to decide if the following characters are a bar-marking or a note-group.
        // Unfortunately, that is ambiguous. Both can contain chord symbols and decorations.
        // If there is a grace note either before or after the chord symbols and decorations, then it is definitely a note-group.
        // If there is a bar marker, it is definitely a bar-marking.
        // If there is either a core-note or chord, it is definitely a note-group.
        // So, loop while we find grace-notes, chords-symbols, or decorations. [It is an error to have more than one grace-note group in a row; the others can be multiple]
        // Then, if there is a grace-note, we know where to go.
        // Else see if we have a chord, core-note, slur, triplet, or bar.

        var ret;
        while (1) {
          ret = tokenizer.eatWhiteSpace(line, i);
          if (ret > 0) {
            i += ret;
          }
          if (i > 0 && line.charAt(i-1) === '\x12') {
            // there is one case where a line continuation isn't the same as being on the same line, and that is if the next character after it is a header.
            ret = header.letter_to_body_header(line, i);
            if (ret[0] > 0) {
              // TODO: insert header here
              i = ret[0];
              multilineVars.start_new_line = false;
            }
          }
          // gather all the grace notes, chord symbols and decorations
          ret = letter_to_spacer(line, i);
          if (ret[0] > 0) {
            i += ret[0];
          }

          ret = letter_to_chord(line, i);
          if (ret[0] > 0) {
            // There could be more than one chord here if they have different positions.
            // If two chords have the same position, then connect them with newline.
            if (!el.chord)
              el.chord = [];
            var chordName = tokenizer.translateString(ret[1]);
            chordName = chordName.replace(/;/g, "\n");
            var addedChord = false;
            for (var ci = 0; ci < el.chord.length; ci++) {
              if (el.chord[ci].position === ret[2]) {
                addedChord = true;
                el.chord[ci].name += "\n" + chordName;
              }
            }
            if (addedChord === false) {
              if (ret[2] === null && ret[3])
                el.chord.push({name: chordName, rel_position: ret[3]});
              else
                el.chord.push({name: chordName, position: ret[2]});
            }

            i += ret[0];
            var ii = tokenizer.skipWhiteSpace(line.substring(i));
            if (ii > 0)
              el.force_end_beam_last = true;
            i += ii;
          } else {
            if (nonDecorations.indexOf(line.charAt(i)) === -1)
              ret = letter_to_accent(line, i);
            else ret = [ 0 ];
            if (ret[0] > 0) {
              if (ret[1] === null) {
                if (i + 1 < line.length)
                  startNewLine();	// There was a ! in the middle of the line. Start a new line if there is anything after it.
              } else if (ret[1].length > 0) {
                if (ret[1].indexOf("style=") === 0) {
                  el.style = ret[1].substr(6);
                } else {
                  if (el.decoration === undefined)
                    el.decoration = [];
                  el.decoration.push(ret[1]);
                }
              }
              i += ret[0];
            } else {
              ret = letter_to_grace(line, i);
              // TODO-PER: Be sure there aren't already grace notes defined. That is an error.
              if (ret[0] > 0) {
                el.gracenotes = ret[1];
                i += ret[0];
              } else
                break;
            }
          }
        }

        ret = letter_to_bar(line, i);
        if (ret[0] > 0) {
          // This is definitely a bar
          if (el.gracenotes !== undefined) {
            // Attach the grace note to an invisible note
            el.rest = { type: 'spacer' };
            el.duration = 0.125; // TODO-PER: I don't think the duration of this matters much, but figure out if it does.
            multilineVars.addFormattingOptions(el, tune.formatting, 'note');
            tune.appendElement('note', startOfLine+i, startOfLine+i+ret[0], el);
            multilineVars.measureNotEmpty = true;
            el = {};
          }
          var bar = {type: ret[1]};
          if (bar.type.length === 0)
            warn("Unknown bar type", line, i);
          else {
            if (multilineVars.inEnding && bar.type !== 'bar_thin') {
              bar.endEnding = true;
              multilineVars.inEnding = false;
            }
            if (ret[2]) {
              bar.startEnding = ret[2];
              if (multilineVars.inEnding)
                bar.endEnding = true;
              multilineVars.inEnding = true;
            }
            if (el.decoration !== undefined)
              bar.decoration = el.decoration;
            if (el.chord !== undefined)
              bar.chord = el.chord;
            if (bar.startEnding && multilineVars.barFirstEndingNum === undefined)
              multilineVars.barFirstEndingNum = multilineVars.currBarNumber;
            else if (bar.startEnding && bar.endEnding && multilineVars.barFirstEndingNum)
              multilineVars.currBarNumber = multilineVars.barFirstEndingNum;
            else if (bar.endEnding)
              multilineVars.barFirstEndingNum = undefined;
            if (bar.type !== 'bar_invisible' && multilineVars.measureNotEmpty) {
              multilineVars.currBarNumber++;
              if (multilineVars.barNumbers && multilineVars.currBarNumber % multilineVars.barNumbers === 0)
                multilineVars.barNumOnNextNote = multilineVars.currBarNumber;
            }
            multilineVars.addFormattingOptions(el, tune.formatting, 'bar');
            tune.appendElement('bar', startOfLine+i, startOfLine+i+ret[0], bar);
            multilineVars.measureNotEmpty = false;
            el = {};
          }
          i += ret[0];
        } else if (line[i] === '&') {	// backtrack to beginning of measure
          warn("Overlay not yet supported", line, i);
          i++;

        } else {
          // This is definitely a note group
          //
          // Look for as many open slurs and triplets as there are. (Note: only the first triplet is valid.)
          ret = letter_to_open_slurs_and_triplets(line, i);
          if (ret.consumed > 0) {
            if (ret.startSlur !== undefined)
              el.startSlur = ret.startSlur;
            if (ret.triplet !== undefined) {
              if (tripletNotesLeft > 0)
                warn("Can't nest triplets", line, i);
              else {
                el.startTriplet = ret.triplet;
                tripletNotesLeft = ret.num_notes === undefined ? ret.triplet : ret.num_notes;
              }
            }
            i += ret.consumed;
          }

          // handle chords.
          if (line.charAt(i) === '[') {
            var chordStartChar = i;
            i++;
            var chordDuration = null;

            var done = false;
            while (!done) {
              var chordNote = getCoreNote(line, i, {}, false);
              if (chordNote !== null) {
                if (chordNote.end_beam) {
                  el.end_beam = true;
                  delete chordNote.end_beam;
                }
                if (el.pitches === undefined) {
                  el.duration = chordNote.duration;
                  el.pitches = [ chordNote ];
                } else	// Just ignore the note lengths of all but the first note. The standard isn't clear here, but this seems less confusing.
                  el.pitches.push(chordNote);
                delete chordNote.duration;

                if (multilineVars.inTieChord[el.pitches.length]) {
                  chordNote.endTie = true;
                  multilineVars.inTieChord[el.pitches.length] = undefined;
                }
                if (chordNote.startTie)
                  multilineVars.inTieChord[el.pitches.length] = true;

                i  = chordNote.endChar;
                delete chordNote.endChar;
              } else if (line.charAt(i) === ' ') {
                // Spaces are not allowed in chords, but we can recover from it by ignoring it.
                warn("Spaces are not allowed in chords", line, i);
                i++;
              } else {
                if (i < line.length && line.charAt(i) === ']') {
                  // consume the close bracket
                  i++;

                  if (multilineVars.next_note_duration !== 0) {
                    el.duration = el.duration * multilineVars.next_note_duration;
                    multilineVars.next_note_duration = 0;
                  }

                  if (multilineVars.inTie) {
                    Common.each(el.pitches, function(pitch) { pitch.endTie = true; });
                    multilineVars.inTie = false;
                  }

                  if (tripletNotesLeft > 0) {
                    tripletNotesLeft--;
                    if (tripletNotesLeft === 0) {
                      el.endTriplet = true;
                    }
                  }

                  var postChordDone = false;
                  while (i < line.length && !postChordDone) {
                    switch (line.charAt(i)) {
                      case ' ':
                      case '\t':
                        addEndBeam(el);
                        break;
                      case ')':
                        if (el.endSlur === undefined) el.endSlur = 1; else el.endSlur++;
                        break;
                      case '-':
                        Common.each(el.pitches, function(pitch) { pitch.startTie = {}; });
                        multilineVars.inTie = true;
                        break;
                      case '>':
                      case '<':
                        var br2 = getBrokenRhythm(line, i);
                        i += br2[0] - 1;	// index gets incremented below, so we'll let that happen
                        multilineVars.next_note_duration = br2[2];
                        if (chordDuration)
                          chordDuration = chordDuration * br2[1];
                        else
                          chordDuration = br2[1];
                        break;
                      case '1':
                      case '2':
                      case '3':
                      case '4':
                      case '5':
                      case '6':
                      case '7':
                      case '8':
                      case '9':
                      case '/':
                        var fraction = tokenizer.getFraction(line, i);
                        chordDuration = fraction.value;
                        i = fraction.index;
                        if (line.charAt(i) === '-' || line.charAt(i) === ')' || line.charAt(i) === ' ' || line.charAt(i) === '<' || line.charAt(i) === '>')
                          i--; // Subtracting one because one is automatically added below
                        else
                          postChordDone = true;
                        break;
                      default:
                        postChordDone = true;
                        break;
                    }
                    if (!postChordDone) {
                      i++;
                    }
                  }
                } else
                  warn("Expected ']' to end the chords", line, i);

                if (el.pitches !== undefined) {
                  if (chordDuration !== null) {
                    el.duration = el.duration * chordDuration;
                  }
                  if (multilineVars.barNumOnNextNote) {
                    el.barNumber = multilineVars.barNumOnNextNote;
                    multilineVars.barNumOnNextNote = null;
                  }
                  multilineVars.addFormattingOptions(el, tune.formatting, 'note');
                  tune.appendElement('note', startOfLine+chordStartChar, startOfLine+i, el);
                  multilineVars.measureNotEmpty = true;
                  el = {};
                }
                done = true;
              }
            }

          } else {
            // Single pitch
            var el2 = {};
            var core = getCoreNote(line, i, el2, true);
            if (el2.endTie !== undefined) multilineVars.inTie = true;
            if (core !== null) {
              if (core.pitch !== undefined) {
                el.pitches = [ { } ];
                // TODO-PER: straighten this out so there is not so much copying: getCoreNote shouldn't change e'
                if (core.accidental !== undefined) el.pitches[0].accidental = core.accidental;
                el.pitches[0].pitch = core.pitch;
                if (core.endSlur !== undefined) el.pitches[0].endSlur = core.endSlur;
                if (core.endTie !== undefined) el.pitches[0].endTie = core.endTie;
                if (core.startSlur !== undefined) el.pitches[0].startSlur = core.startSlur;
                if (el.startSlur !== undefined) el.pitches[0].startSlur = el.startSlur;
                if (core.startTie !== undefined) el.pitches[0].startTie = core.startTie;
                if (el.startTie !== undefined) el.pitches[0].startTie = el.startTie;
              } else {
                el.rest = core.rest;
                if (core.endSlur !== undefined) el.endSlur = core.endSlur;
                if (core.endTie !== undefined) el.rest.endTie = core.endTie;
                if (core.startSlur !== undefined) el.startSlur = core.startSlur;
                if (core.startTie !== undefined) el.rest.startTie = core.startTie;
                if (el.startTie !== undefined) el.rest.startTie = el.startTie;
              }

              if (core.chord !== undefined) el.chord = core.chord;
              if (core.duration !== undefined) el.duration = core.duration;
              if (core.decoration !== undefined) el.decoration = core.decoration;
              if (core.graceNotes !== undefined) el.graceNotes = core.graceNotes;
              delete el.startSlur;
              if (multilineVars.inTie) {
                if (el.pitches !== undefined) {
                  el.pitches[0].endTie = true;
                  multilineVars.inTie = false;
                } else if (el.rest.type !== 'spacer') {
                  el.rest.endTie = true;
                  multilineVars.inTie = false;
                }
              }
              if (core.startTie || el.startTie)
                multilineVars.inTie = true;
              i  = core.endChar;

              if (tripletNotesLeft > 0) {
                tripletNotesLeft--;
                if (tripletNotesLeft === 0) {
                  el.endTriplet = true;
                }
              }

              if (core.end_beam)
                addEndBeam(el);

              // If there is a whole rest, then it should be the duration of the measure, not it's own duration. We need to special case it.
              if (el.rest && el.rest.type === 'rest' && el.duration === 1) {
                el.rest.type = 'whole';

                el.duration = durationOfMeasure(multilineVars);
              }

              if (multilineVars.barNumOnNextNote) {
                el.barNumber = multilineVars.barNumOnNextNote;
                multilineVars.barNumOnNextNote = null;
              }
              multilineVars.addFormattingOptions(el, tune.formatting, 'note');
              tune.appendElement('note', startOfLine+startI, startOfLine+i, el);
              multilineVars.measureNotEmpty = true;
              el = {};
            }
          }

          if (i === startI) {	// don't know what this is, so ignore it.
            if (line.charAt(i) !== ' ' && line.charAt(i) !== '`')
              warn("Unknown character ignored", line, i);
            i++;
          }
        }
      }
    }
  }
760226
def parse(date_time)
      raise(ISO8601::Errors::UnknownPattern, date_time) if date_time.empty?

      date, time = date_time.split('T')

      date_atoms = parse_date(date)
      time_atoms = Array(time && parse_time(time))
      separators = [date_atoms.pop, time_atoms.pop]

      raise(ISO8601::Errors::UnknownPattern, @original) unless valid_representation?(date_atoms, time_atoms)
      raise(ISO8601::Errors::UnknownPattern, @original) unless valid_separators?(separators)

      ::DateTime.new(*(date_atoms + time_atoms).compact)
    end
712549
def dt_from_header(date_str):
    
    convert_fns = (
        dt_from_rfc8601,
        dt_from_rfc1123,
    )

    for convert_fn in convert_fns:
        try:
            return convert_fn(date_str)
        except ValueError:
            pass

    return None
770407
def parsetime(s):
    
    try:
        fields = s.split('.')
        subfields = fields[0].split(':')
        H = int(subfields[0])
        M = int(subfields[1])
        S = int(subfields[2])
        if len(subfields) > 3:
            m = int(subfields[3])
        else:
            m = 0
        if len(fields) > 1:
            m = int(fields[1])
        return (H,M,S,m)
    except:
        raise ValueError("Invalid timestamp, must be in HH:MM:SS.mmm format: " + s)
551712
def parse_headers(header_data_for_multiple_responses)
      @headers = {}

      responses = Patron::HeaderParser.parse(header_data_for_multiple_responses)
      last_response = responses[-1] # Only use the last response (for proxies and redirects)

      @status_line = last_response.status_line
      last_response.headers.each do |line|
        hdr, val = line.split(":", 2)

        val.strip! unless val.nil?

        if @headers.key?(hdr)
          @headers[hdr] = [@headers[hdr]] unless @headers[hdr].kind_of? Array
          @headers[hdr] << val
        else
          @headers[hdr] = val
        end
      end
    end
1019304
function (line) {
    var pieces = line.split(' ')

    // Header string pieces
    var output = {
      version: pieces.shift(),
      status: parseFloat(pieces.shift()),
      statusText: pieces.join(' ')
    }

    return output
  }
863518
def _parse_header(self):
        """"""
        self.print("Parsing the DETX header")
        self._det_file.seek(0, 0)
        first_line = self._readline()
        try:
            self.det_id, self.n_doms = split(first_line, int)
            self.version = 'v1'
        except ValueError:
            det_id, self.version = first_line.split()
            self.det_id = int(det_id)
            validity = self._readline().strip()
            self.valid_from, self.valid_until = split(validity, float)
            raw_utm_info = self._readline().strip().split(' ')
            try:
                self.utm_info = UTMInfo(*raw_utm_info[1:])
            except TypeError:
                log.warning("Missing UTM information.")
            n_doms = self._readline()
            self.n_doms = int(n_doms)