示例#1
0
  /**
   * Split one line in a CSV file into its rows. Comma's appearing in double quoted strings will not
   * be seen as a separator.
   *
   * @return
   * @throws IOException
   * @throws FHIRException @
   */
  protected String[] parseLine() throws IOException, FHIRException {
    List<String> res = new ArrayList<String>();
    StringBuilder b = new StringBuilder();
    boolean inQuote = false;

    while (inQuote || (peek() != '\r' && peek() != '\n')) {
      char c = peek();
      next();
      if (c == '"') inQuote = !inQuote;
      else if (!inQuote && c == ',') {
        res.add(b.toString().trim());
        b = new StringBuilder();
      } else b.append(c);
    }
    res.add(b.toString().trim());
    while (ready() && (peek() == '\r' || peek() == '\n')) {
      next();
    }

    String[] r = new String[] {};
    r = res.toArray(r);
    return r;
  }
示例#2
0
 private char peek() throws FHIRException, IOException {
   if (state == 0) next();
   if (state == 1) return pc;
   else throw new FHIRException("read past end of source");
 }