Parse a list of exported variables.
@param line a non-null line
@return a non-null map of exported variables
545127
public static Map<String,ExportedVariable> parseExportedVariables( String line ) {

		Pattern randomPattern = Pattern.compile( ParsingConstants.PROPERTY_GRAPH_RANDOM_PATTERN, Pattern.CASE_INSENSITIVE );
		Pattern varPattern = Pattern.compile( "([^,=]+)(\\s*=\\s*(\"([^\",]+)\"|([^,]+)))?" );

		Map<String,ExportedVariable> result = new LinkedHashMap<> ();
		Matcher varMatcher = varPattern.matcher( line );
		while( varMatcher.find()) {

			String key = varMatcher.group( 1 ).trim();
			if( Utils.isEmptyOrWhitespaces( key ))
				continue;

			String value = null;
			if( varMatcher.group( 3 ) != null ) {

				// We do not always trim!
				// Surrounding white spaces are kept when defined between quotes.
				if( varMatcher.group( 5 ) != null )
					value = varMatcher.group( 5 ).trim();
				else
					value = varMatcher.group( 4 );
			}

			ExportedVariable var = new ExportedVariable();
			Matcher m = randomPattern.matcher( key );
			if( m.matches()) {
				var.setRandom( true );
				var.setRawKind( m.group( 1 ));
				key = m.group( 2 ).trim();
			}

			var.setName( key.trim());
			if( value != null )
				var.setValue( value );

			result.put( var.getName(), var );
		}

		return result;
	}
257234
protected void computeVariablesFromObject(MtasParserObject object,
      Map<String, List<MtasParserObject>> currentList,
      Map<String, Map<String, String>> variables) {
    MtasParserType<MtasParserVariable> parserType = object.getType();
    String id = object.getId();
    if (id != null) {
      for (MtasParserVariable variable : parserType.getItems()) {
        if (!variables.containsKey(variable.variable)) {
          variables.put(variable.variable, new HashMap<String, String>());
        }
        StringBuilder builder = new StringBuilder();
        for (MtasParserVariableValue variableValue : variable.values) {
          if (variableValue.type.equals("attribute")) {
            String subValue = object.getAttribute(variableValue.name);
            if (subValue != null) {
              builder.append(subValue);
            }
          }
        }
        variables.get(variable.variable).put(id, builder.toString());
      }
    }
  }
685382
private static Var parseVar(String varLine) {
        String[] ws = whitespace.split(varLine);
        String name = ws[0];
        List<String> stateNames = Arrays.asList(comma.split(ws[1]));
        int numStates = stateNames.size();
        return new Var(VarType.PREDICTED, numStates, name, stateNames);
    }
945143
public NmeaMessage parse(String line) {
        LinkedHashMap<String, String> tags = Maps.newLinkedHashMap();

        String remaining;
        if (line.startsWith("\\")) {
            int tagFinish = line.lastIndexOf('\\', line.length() - 1);
            if (tagFinish == -1)
                throw new NmeaMessageParseException(
                        "no matching \\ symbol to finish tag block: " + line);
            if (tagFinish == 0)
                throw new NmeaMessageParseException("tag block is empty or not terminated");
            tags = extractTags(line.substring(1, tagFinish));
            remaining = line.substring(tagFinish + 1);
        } else
            remaining = line;

        String[] items;
        String checksum;
        if (remaining.length() > 0) {
            if (!remaining.contains("*"))
                throw new NmeaMessageParseException("checksum delimiter * not found");
            items = getNmeaItems(remaining);
            // TODO validate message using checksum
            checksum = line.substring(line.indexOf('*') + 1);
        } else {
            items = new String[] {};
            // TODO decide what value to put here
            checksum = "";
        }

        return new NmeaMessage(tags, Arrays.asList(items), checksum);
    }
903117
private Optional<SqlCommandCall> parseCommand(String line) {
		final Optional<SqlCommandCall> parsedLine = SqlCommandParser.parse(line);
		if (!parsedLine.isPresent()) {
			printError(CliStrings.MESSAGE_UNKNOWN_SQL);
		}
		return parsedLine;
	}
591759
static Property parse(final String line) throws IOException {
        if (!line.startsWith("property ")) {
            throw new IOException("not a property: '"
                    + line + "'");
        }
        String definition = line.substring("property ".length());
        definition = definition.trim();

        if (!definition.startsWith("list ")) {
            throw new IllegalArgumentException("not a list property: '"
                    + line + "'");
        }
        definition = definition.substring("list ".length());
        definition = definition.trim();

        String[] parts = definition.split(" +", 3);
        if (parts.length != 3) {
            throw new IOException("Expected three parts in list property "
                    + "definition: '" + line + "'");
        }
        String countType = parts[0];
        String type = parts[1];
        String name = parts[2];

        DataType dataType;
        DataType countDataType;
        try {
            dataType = DataType.parse(type);
            countDataType = DataType.parse(countType);
        }
        catch (IllegalArgumentException e) {
            throw new IOException(e.getMessage());
        }

        return new ListProperty(countDataType, name, dataType);
    }
1363600
public static String[] parseListRecord(String line) {
        // return null if line is blank
        if (noLength(line)) {
            return null;
        }

        // trim away leading / trailing whitespace from list record
        line = line.trim();

        // remove list boundaries
        if (line.startsWith("{")) {
            line = line.substring(1);
        }
        if (line.endsWith("}")) {
            line = line.substring(0, line.length() - 1);
        }

        // return no fields if list record is empty
        if (line.trim().length() == 0) {
            return new String[0];
        }

        // split fields
        final CharacterIterator chit = new StringCharacterIterator(line);
        final List<String> fields = new ArrayList<String>();
        final StringBuilder fb = new StringBuilder();
        boolean inField = false;
        for (char c = chit.first(); c != CharacterIterator.DONE; c = chit
                .next()) {
            if (!inField && c == FIELD_BOUNDARY) {
                inField = true;
                fb.setLength(0);
            } else if (inField && c == FIELD_BOUNDARY) {
                int mark = chit.getIndex();
                char previousChar = chit.previous();
                if (previousChar == ESCAPE) {
                    fb.deleteCharAt(fb.length() - 1);
                    fb.append(c);
                } else {
                    inField = false;
                }
                chit.setIndex(mark);
            } else if (!inField && c == FIELD_SEPARATOR) {
                fields.add(fb.toString());
            } else if (inField) {
                fb.append(c);
            }
        }

        if (!line.endsWith(",")) {
            fields.add(fb.toString());
        }

        return fields.toArray(new String[fields.size()]);
    }
826168
function parseVariable(str, line) {
    var tokens = lexer.read(utils.strip(str)),
      parser,
      out;

    parser = new TokenParser(tokens, filters, escape, line, opts.filename);
    out = parser.parse().join('');

    if (parser.state.length) {
      utils.throwError('Unable to parse "' + str + '"', line, opts.filename);
    }

    /**
     * A parsed variable token.
     * @typedef {object} VarToken
     * @property {function} compile Method for compiling this token.
     */
    return {
      compile: function () {
        return '_output += ' + out + ';\n';
      }
    };
  }
495589
public static CaptureSearchResult parseCDXLineFlex(String line) {
		CaptureSearchResult result = new CaptureSearchResult();
		return parseCDXLineFlex(line, result);
	}
975084
public static String[] parse(final String line) {
        boolean insideQuote = false;
        final ArrayList<String> result = new ArrayList<>();
        int quoteCount = 0;
        final StringBuilder sb = new StringBuilder();
        for (int i = 0; i < line.length(); i++) {
            final char c = line.charAt(i);

            if (c == QUOTE) {
                insideQuote = !insideQuote;
                quoteCount++;
            }

            if (c == COMMA && !insideQuote) {
                String value = sb.toString();
                value = unQuoteUnEscape(value);
                result.add(value);
                sb.setLength(0);
                continue;
            }

            sb.append(c);
        }

        result.add(sb.toString());

        // Validate
        if (quoteCount % 2 != 0) {
            return new String[0];
        }

        return result.toArray(new String[result.size()]);
    }
286646
function parseLine(line){
  var len = line.length;
  var i = 0;
  var lineArr = [];
  var preIndex = 0;
  var isEmpty = false;
  for(; i < len; i++){
    if(/\s/.test(line[i])){
      if(!isEmpty){
        lineArr.push(line.substr(preIndex, i - preIndex));
        isEmpty = true; 
      }
    }else{
      if(isEmpty){
        if(lineArr.length === FIXED_LEN){
          lineArr.push(line.substr(i));
          break;
        }else{
          isEmpty = false;
          preIndex = i;
        }
      }
    }
  }
  return lineArr;
}
1110093
public static StringValueMap fromString(String line) {
		StringValueMap result = new StringValueMap();
		if (line == null || line.length() == 0)
			return result;

		// Todo: User tokenizer / decoder
		String[] tokens = line.split(";", -1);

		for (String token : tokens) {
			if (token.length() == 0)
				continue;
			int index = token.indexOf('=');
			String key = index > 0 ? token.substring(0, index).trim() : token.trim();
			String val = index > 0 ? token.substring(index + 1).trim() : null;
			result.put(key, val);
		}

		return result;
	}
1105871
@Override
	protected List<String> getVariablesToIgnore() {

		List<String> variablesToIgnore = new ArrayList<> ();
		variablesToIgnore.add( "^" + Pattern.quote( MILLI_TIME ) + "$" );
		variablesToIgnore.add( "^" + Pattern.quote( NANO_TIME ) + "$" );
		variablesToIgnore.add( "^" + Pattern.quote( SMART_INDEX ) + "$" );
		variablesToIgnore.add( "^" + Pattern.quote( RANDOM_UUID ) + "$" );

		for( String var : this.context.variables.keySet())
			variablesToIgnore.add( "^\\$\\(" + Pattern.quote( var ) + "\\)$" );

		variablesToIgnore.add( "^" + Pattern.quote( FORMATTED_TIME_PREFIX ) + "[^)]*\\)$" );
		variablesToIgnore.add( "^" + Pattern.quote( EXISTING_INDEX_PREFIX ) + "[^)]*\\)$" );
		return variablesToIgnore;
	}


	/**
	 * Extracts the date pattern for a "formatted time" variable.
	 * @param group a formatted time
	 * @return a non-null string
	 */
	static String extractDatePattern( String group ) {
		return group.substring( FORMATTED_TIME_PREFIX.length(), group.length() - 2 ).trim();
	}


	/**
	 * Replaces variables in instance names.
	 * @param value an expression that can reference other variables (not null)
	 * @param context a context (not null)
	 * @param parentInstancePath the parent instance path (may be null)
	 * @param context a non-null map with context information
	 * @return the updated value, or null if an <code>$(existing_index ...)</code> variable failed to be resolved
	 */
	static String replaceVariables( String value, Context context, String parentInstancePath ) {

		long nanoTime = System.nanoTime();
		long milliTime = TimeUnit.MILLISECONDS.convert( nanoTime, TimeUnit.NANOSECONDS );

		// Simple replacements
		value = value.replace( NANO_TIME, String.valueOf( nanoTime ));
		value = value.replace( MILLI_TIME, String.valueOf( milliTime ));
		value = value.replace( RANDOM_UUID, UUID.randomUUID().toString());

		// A little more complex
		if( value.startsWith( FORMATTED_TIME_PREFIX )
				&& value.endsWith( ")" )) {

			String datePattern = extractDatePattern( value );
			SimpleDateFormat sdf = new SimpleDateFormat( datePattern );

			// We replace the whole value as such variables were validated and span over a entire line
			value = sdf.format( new Date( milliTime ));
		}

		// Even more complex
		int smartCpt = 0;
		if( value.contains( SMART_INDEX )) {
			for( int cpt = 1; smartCpt == 0; cpt++ ) {
				String testName = value.replace( SMART_INDEX, String.valueOf( cpt ));
				String testPath = "/" + testName;
				if( parentInstancePath != null )
					testPath = parentInstancePath + testPath;

				if( ! context.instanceExists( testPath )) {
					smartCpt = cpt;
				}
			}
		}

		value = value.replace( SMART_INDEX, String.valueOf( smartCpt ));

		// To perform in last: deal with existing indexes
		boolean disabled = false;
		Pattern fullPattern = Pattern.compile( EXISTING_INDEX_PATTERN );
		Matcher m = fullPattern.matcher( value );
		if( value.contains( EXISTING_INDEX_PREFIX )
				&& m.matches()) {

			String minOrMax = m.group( 2 );
			String prefix = m.group( 1 );
			String suffix = m.group( 6 );
			String bound = m.group( 5 );
			String instanceNamePattern = "/" + prefix + "(\\d+)" + suffix;
			if( parentInstancePath != null )
				instanceNamePattern = parentInstancePath + instanceNamePattern;

			// Find the index
			int cpt = findIndex( instanceNamePattern, context, bound, "MIN".equals( minOrMax ));

			// If cpt is negative, do not replace anything, nothing matches the requirements.
			// We just return null for the variable's value.
			if( cpt < 0 )
				disabled = true;
			else
				value = m.replaceAll( "$1" + String.valueOf( cpt ) + "$6" );
		}

		// Disabled variable => return null
		if( disabled )
			value = null;

		// Inject other variables, if necessary.
		// Disabled variables are contagious, this is managed during the parsing.
		else
			value = CommandsParser.injectContextVariables( value, context.variables );

		return value;
	}


	/**
	 * @param instanceNamePattern
	 * @param context
	 * @param bound
	 * @param findMinimum true to get the minimum value, false for the maximum
	 * @return -1 if no matching instance was found, a positive integer otherwise
	 */
	private static int findIndex( String instanceNamePattern, Context context, String bound, boolean findMinimum ) {

		// Find all the matching indexes?
		Pattern pattern = Pattern.compile( instanceNamePattern );
		SortedSet<Integer> foundIndexes = new TreeSet<> ();
		for( String instancePath : context.instancePathToComponentName.keySet()) {
			Matcher m = pattern.matcher( instancePath );
			if( ! m .find())
				continue;

			int index = Integer.parseInt( m.group( 1 ));
			foundIndexes.add( index );
		}

		// Exclude indexes that are out of bound
		if( bound != null ) {
			bound = bound.trim();
			int min = 0, max = Integer.MAX_VALUE;
			int value = Integer.parseInt( bound.substring( 1 ).trim());
			if( '<' == bound.charAt( 0 ))
				max = value;
			else
				min = value;

			Set<Integer> toRemove = new HashSet<> ();
			for( Integer index : foundIndexes ) {
				if( index <= min || index >= max )
					toRemove.add( index );
			}

			foundIndexes.removeAll( toRemove );
		}

		// Eventually, decide whether we want the tail or the head
		int result;
		if( foundIndexes.isEmpty())
			result = -1;
		else if( findMinimum )
			result = foundIndexes.first();
		else
			result = foundIndexes.last();

		return result;
	}
1006847
public void parse( String line, File sourceFile, int lineNumber ) {

		// Reset
		this.rawNameToVariables.clear();
		this.errors.clear();
		this.cursor = 0;

		// Parse
		while( this.cursor < line.length()) {

			char c = line.charAt( this.cursor );
			if( Character.isWhitespace( c ) || c == ',' )
				this.cursor ++;

			recognizeVariable( line, sourceFile, lineNumber );
		}
	}
809464
public static String[] getDataFromLine(final String line, final String seperator)
	{
		final String[] splittedLine = line.split(seperator);
		return splittedLine;
	}
936710
public synchronized void parseLine(String line) throws SyntaxErrorException
	{
		if (null != getParserOutcome() && isParserOutcomeMultipleLine())
		{
			parseLine__multipleLineMode(line);
		}
		else
		{
			parseLine__singleLineMode(line);
		}
	}
349728
public static FilterParams fromString(String line) {
		StringValueMap map = StringValueMap.fromString(line);
		return new FilterParams(map);
	}