Surround the given CSV data with quotations for every field.

@param csvData The original data without quotations.
@return A new string object with all fields being quoted.
970511
private String surroundFields(String csvData) {

        StringBuilder surroundedCSV = null;
        StringTokenizer currTokenizer = null;

        surroundedCSV = new StringBuilder();

        for (String currLine : csvData.split(BREAK)) {

            currTokenizer = new StringTokenizer(currLine, SEP);

            while (currTokenizer.hasMoreTokens()) {

                surroundedCSV.append(QUOTATION).append(currTokenizer.nextToken()).append(QUOTATION);

                if (currTokenizer.hasMoreTokens())
                    surroundedCSV.append(SEP);
            }

            surroundedCSV.append(BREAK);
        }

        return surroundedCSV.toString();
    }
850343
public void onCDATA (@Nullable final String sText)
  {
    if (StringHelper.hasText (sText))
    {
      if (sText.indexOf (CDATA_END) >= 0)
      {
        // Split CDATA sections if they contain the illegal "]]>" marker
        final ICommonsList <String> aParts = StringHelper.getExploded (CDATA_END, sText);
        final int nParts = aParts.size ();
        for (int i = 0; i < nParts; ++i)
        {
          _append (CDATA_START);
          if (i > 0)
            _append ('>');
          _appendMasked (EXMLCharMode.CDATA, aParts.get (i));
          if (i < nParts - 1)
            _append ("]]");
          _append (CDATA_END);
        }
      }
      else
      {
        // No special handling required
        _append (CDATA_START)._appendMasked (EXMLCharMode.CDATA, sText)._append (CDATA_END);
      }
    }
  }
801489
public static String getCdataSection(String cdataContent)
	{
		StringBuffer _result = new StringBuffer();
		return doAppendCdataSection(_result, cdataContent).toString();
	}
304750
function(sData) {
				sData = "" + sData;
				mData["text/plain"] = sData;
				mData["text"] = sData;
				setTransferData("text/plain", sData);
				setTransferData("text", sData);
			}
1342076
public String storeData(String cookieData) {
        try {
            String token = generateToken();
            ensureSpaceExists();
            s3StorageProvider.addHiddenContent(this.hiddenSpaceName, token, Constants.MEDIA_TYPE_APPLICATION_JSON,
                                               IOUtil.writeStringToStream(cookieData));
            return token;
        } catch (Exception e) {
            throw new DuraCloudRuntimeException(e);
        }
    }
868651
public static String quoteHtmlChars(String item) {
    if (item == null) {
      return null;
    }
    byte[] bytes = item.getBytes();
    if (needsQuoting(bytes, 0, bytes.length)) {
      ByteArrayOutputStream buffer = new ByteArrayOutputStream();
      try {
        quoteHtmlChars(buffer, bytes, 0, bytes.length);
      } catch (IOException ioe) {
        // Won't happen, since it is a bytearrayoutputstream
      }
      return buffer.toString();
    } else {
      return item;
    }
  }
1220195
public Csv lineDelimiter(String delimiter) {
		Preconditions.checkNotNull(delimiter);
		internalProperties.putString(FORMAT_LINE_DELIMITER, delimiter);
		return this;
	}
567535
public void writeData(String data) {
        _buffer.append("<![CDATA[");
        _buffer.append( data);
        _buffer.append( "]]>");
    }
51077
private static String getTableHtml(String csvData, String delimiter) throws IOException {

        String lineSeparator = System.getProperty("line.separator");
        int tmpindex = csvData.indexOf(lineSeparator);
        String formatString = (tmpindex >= 0) ? csvData.substring(0, tmpindex) : csvData;

        if (delimiter == null) {
            delimiter = getPreferredDelimiter(csvData);
        }

        StringBuffer xml = new StringBuffer("<table>");
        if (isFormattingInformation(formatString, delimiter)) {
            // transform formatting to HTML colgroup
            xml.append(getColGroup(formatString, delimiter));
            // cut of first line
            csvData = csvData.substring(formatString.length() + lineSeparator.length());
        }

        String line;
        BufferedReader br = new BufferedReader(new StringReader(csvData));
        while ((line = br.readLine()) != null) {
            xml.append("<tr>\n");

            // must use tokenizer with delimiters include in order to handle empty cells appropriately
            StringTokenizer t = new StringTokenizer(line, delimiter, true);
            boolean hasValue = false;
            while (t.hasMoreElements()) {
                String item = (String)t.nextElement();
                if (!hasValue) {
                    xml.append("\t<td>");
                    hasValue = true;
                }
                if (!item.equals(delimiter)) {

                    // remove enclosing delimiters
                    item = removeStringDelimiters(item);

                    // in order to allow links, lines starting and ending with tag delimiters (< ...>) remains unescaped
                    if (item.startsWith(TAG_START_DELIMITER) && item.endsWith(TAG_END_DELIMITER)) {
                        xml.append(item);
                    } else {
                        xml.append(CmsStringUtil.escapeHtml(item));
                    }
                } else {
                    xml.append("</td>\n");
                    hasValue = false;
                }
            }
            if (hasValue) {
                xml.append("</td>\n");
            } else {
                xml.append("<td></td>\n");
            }

            xml.append("</tr>\n");
        }

        return xml.append("</table>").toString();
    }
1187021
public CsvData read(Reader reader) throws IORuntimeException {
		final CsvParser csvParser = parse(reader);

		final List<CsvRow> rows = new ArrayList<>();
		CsvRow csvRow;
		while ((csvRow = csvParser.nextRow()) != null) {
			rows.add(csvRow);
		}

		final List<String> header = config.containsHeader ? csvParser.getHeader() : null;
		return new CsvData(header, rows);
	}
719415
public CsvData read(File file, Charset charset) throws IORuntimeException {
		return read(Objects.requireNonNull(file.toPath(), "file must not be null"), charset);
	}
617513
static List<String> csvLines(Reader reader) {
        // This needs to handle quoted text that spans multiple lines,
        // so we divide the full text into chunks that correspond to
        // a single csv line
        try {
            BufferedReader br = new BufferedReader(reader);
            List<String> lines = new ArrayList<>();
            // The current line read from the Reader
            String line;
            // The full csv line that may span multiple lines
            String longLine = null;
            while ((line = br.readLine()) != null) {
                // If we have a line from the previous iteration,
                // we concatenate it
                if (longLine == null) {
                    longLine = line;
                } else {
                    longLine = longLine.concat("\n").concat(line);
                }
                // Count the number of quotes: if it's even, the csv line
                // must end here. If not, it will continue to the next
                if (isEvenQuotes(longLine)) {
                    lines.add(longLine);
                    longLine = null;
                }
            }
            // If there is text leftover, the line was not closed propertly.
            // XXX: we need to figure out how to handle errors like this
            if (longLine != null) {
                lines.add(longLine);
            }
            return lines;
        } catch(IOException ex) {
            throw new RuntimeException("Couldn't process data", ex);
        }
    }
1031397
public static void logCSV(String csvData, final Logger log) {

        log.info("");
        log.info("**** Here we go with CSV:");
        log.info("");
        log.info(csvData);
        log.info("");
        log.info("**** End of CSV data. Have a nice day!");
        log.info("");
        LogHelper.moo(log);
    }
426853
protected Expression string(Data data) throws TemplateException {

	// check starting character for a string literal
	if (!data.srcCode.isCurrent('"') && !data.srcCode.isCurrent('\'')) return null;
	Position line = data.srcCode.getPosition();

	// Init Parameter
	char quoter = data.srcCode.getCurrentLower();
	StringBuilder str = new StringBuilder();
	Expression expr = null;

	while (data.srcCode.hasNext()) {
	    data.srcCode.next();
	    // check sharp
	    if (data.srcCode.isCurrent('#')) {

		// Ecaped sharp
		if (data.srcCode.isNext('#')) {
		    data.srcCode.next();
		    str.append('#');
		}
		// get Content of sharp
		else {
		    data.srcCode.next();
		    comments(data);
		    Expression inner = assignOp(data);
		    comments(data);
		    if (!data.srcCode.isCurrent('#')) throw new TemplateException(data.srcCode, "Invalid Syntax Closing [#] not found");

		    ExprString exprStr = null;
		    if (str.length() != 0) {
			exprStr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
			if (expr != null) {
			    expr = data.factory.opString(expr, exprStr);
			}
			else expr = exprStr;
			str = new StringBuilder();
		    }
		    if (expr == null) {
			expr = inner;
		    }
		    else {
			expr = data.factory.opString(expr, inner);
		    }
		}
	    }
	    // check quoter
	    else if (data.srcCode.isCurrent(quoter)) {
		// Ecaped sharp
		if (data.srcCode.isNext(quoter)) {
		    data.srcCode.next();
		    str.append(quoter);
		}
		// finsish
		else {
		    break;
		}
	    }
	    // all other character
	    else {
		str.append(data.srcCode.getCurrent());
	    }
	}
	if (!data.srcCode.forwardIfCurrent(quoter)) throw new TemplateException(data.srcCode, "Invalid Syntax Closing [" + quoter + "] not found");

	if (expr == null) expr = data.factory.createLitString(str.toString(), line, data.srcCode.getPosition());
	else if (str.length() != 0) {
	    expr = data.factory.opString(expr, data.factory.createLitString(str.toString(), line, data.srcCode.getPosition()));
	}
	comments(data);

	if (expr instanceof Variable) {
	    Variable var = (Variable) expr;
	    var.fromHash(true);
	}

	return expr;

    }
292774
function csvToMapping(csvString) {
  const lines = csvString.split(/\n|\r|\r\n/);
  const header = lines.shift().split(',');
  const key = header.shift();
  const now = new Date();
  const headerIdx = [];
  const fields = [];
  header.forEach((h, i) => {
    if (h === '') return;
    headerIdx.push(i);
    fields.push({key: h, format: 'text'});
  });
  const mapping = {
    created: now.toString(),
    fields: fields,
    key: key,
    mapping: {}
  };
  lines.forEach(line => {
    const values = line.split(',');
    const k = values.shift();
    mapping.mapping[k] = Array(headerIdx.length);
    headerIdx.forEach(i => {
      mapping.mapping[k][i] = values[i];
    });
  });
  return mapping;
}
1056734
function csv2json(csvData) {
  var result = {};
  var csvLines = csvData.toString().split('\n');
  for (var i in csvLines) {
    var fields = splitCsvLine(csvLines[i]);
    if (fields.length) {
      var key = '';
      for (var k = 0; k < fields.length - 1; k++) {
        if (fields[k].length) {
          key += '.' + fields[k];
        }
      }
      result[key.substr(1)] = fields[fields.length - 1];
    }
  }
  return result;
}
1188292
public static List<Object> parseCSVLine(String line, String separatorChar) {
        String regex = // puts a doublequoted field in group(1) and an unquoted field into group(2)
                "\\G(?:^|" + separatorChar + ")" +
                "(?:" +
                "\"" +
                "((?:[^\"]++|\"\")*+)" +
                "\"" +
                "|" +
                "([^\"" + separatorChar + "]*)" +
                ")";
        Matcher mMain = Pattern.compile(regex).matcher("");
        Matcher mQuote = Pattern.compile("\"\"").matcher("");
        Matcher mDouble = Pattern.compile(DOUBLE_REGEX_WITH_NAN).matcher("");
        
        List<Object> values = new ArrayList<>();
        mMain.reset(line);
        while (mMain.find()) {
            Object value;
            if (mMain.start(2) >= 0) {
                String field = mMain.group(2);
                if (mDouble.reset(field).matches()) {
                    value = Double.parseDouble(field);
                } else {
                    value = field;
                }
            } else {
                // If quoted, always use string
                value = mQuote.reset(mMain.group(1)).replaceAll("\"");
            }
            values.add(value);
        }
        return values;
    }