Pattern matching.

@param ptnName the ptn name
@param input the input
@return the string
967722
private static String patternMatching(String ptnName, String input) {
		String suffix = "";
		if (ptnNumber == null)
			patternCompile();

		Matcher matcher;
		if (ptnName.equals("number")) {
			matcher = ptnNumber.matcher(input);
			if (matcher.matches())
				suffix = ":number";
		} else if (ptnName.equals("short_date")) {
			matcher = ptnShortDate.matcher(input);
			if (matcher.matches())
				suffix = ":short-date";
		} else if (ptnName.equals("long_date")) {
			matcher = ptnLongDate.matcher(input);
			if (matcher.matches())
				suffix = ":long-date";
		} else if (ptnName.equals("percentage")) {
			matcher = ptnPercentage.matcher(input);
			if (matcher.matches())
				suffix = ":percentage";
		} else if (ptnName.equals("currency")) {
			matcher = ptnCurrency.matcher(input);
			if (matcher.matches())
				suffix = ":currency";
			else {
				matcher = ptnViCurrency.matcher(input);
				if (matcher.matches()) {
					suffix = ":currency";
				}
			}
		}
		return suffix;
	}
224973
public String processInput(String input) {

        JsonObject object;
        try {
            object = gs.fromJson(input, JsonObject.class);
        } catch (Throwable t) {
            return "{ \"status\" : \"fail\", \"error\" : \"Failed to parse input\" }";
        }

        String command = object.get("command").getAsString();
        JsonObject payload;
        if (!object.has("payload")) {
            payload = new JsonObject();
        } else {
            payload = object.get("payload").getAsJsonObject();
        }

        CommandStatus status;

        try {
            status = dispatch(command, payload);
        } catch (Throwable t) {
            status = new CommandStatus();
            status.fail(t).setPayload(payload);
        }

        return status.toString();
    }
452977
public static String[] asStringArray(List<String> input) {
		String[] result = new String[input.size()];

		for (int i = 0; i < result.length; i++) {
			result[i] = input.get(i);
		}

		return result;
	}
711347
private static String patternToString(@Nullable final Pattern pattern) {
		return pattern != null ? pattern.pattern() + " (flags: " + pattern.flags() + ")" : NO_PATTERN_PLACEHOLDER;
	}
703009
public static String decode(final String input) {
		return new String(decode(input.getBytes(charsetISOLatin1)), charsetUTF8);
	}
754573
public boolean matches(CharSequence input) {
        separatorCount = -1;
        separatorIndex = 0;

        if (input == null) {
            this.input = null;
            separatorFlags = null;
            return false;
        }

        this.input = input;
        separatorFlags = new int[input.length()];

        boolean result = matches(pattern, input, separatorFlags);

        if (result) {
            for (int i = separatorFlags.length - 1; i >= 0; i--) {
                if (separatorFlags[i] > 0) {
                    separatorCount = separatorFlags[i];
                    break;
                }
            }
        }

        return result;
    }
304448
public static Maybe<Pair<Node<PluralType>, CharSequence>> parse(String input) {
    return P_RULE.parse(input);
  }
96034
public static String rightTrim(CharSequence input) {
      if (input == null) {
         return null;
      }
      return StringFunctions.RIGHT_TRIM.apply(input.toString());
   }
896080
private boolean exactMatch(String str, int i) {
    int end = str.length() - i;
    for (String p : _patterns) {
      int start = end - p.length();
      if (start >= 0 && str.regionMatches(start, p, 0, p.length())) {
        return true;
      }
    }
    return false;
  }
548644
public static String matchImplicit(Pointer ptr, int len) {
       String tag = "str";
       int cs;
       int act;
       int have = 0;
       int nread = 0;
       int p=ptr.start;
       int pe = p+len;
       int eof = p+len;
       int tokstart = -1;
       int tokend = -1;

       byte[] data = ptr.buffer;
       if(len == 0) {
         data = new byte[]{(byte)'~'};
         p = 0;
         pe = 1;
         eof = 1;
       }
              

// line 319 "src/main/org/yecht/ImplicitScanner2.java"
	{
	cs = ImplicitScanner_start;
	}
// line 104 "src/main/org/yecht/ImplicitScanner2.rl"


// line 326 "src/main/org/yecht/ImplicitScanner2.java"
	{
	int _klen;
	int _trans = 0;
	int _keys;
	int _goto_targ = 0;

	_goto: while (true) {
	switch ( _goto_targ ) {
	case 0:
	if ( p == pe ) {
		_goto_targ = 4;
		continue _goto;
	}
	if ( cs == 0 ) {
		_goto_targ = 5;
		continue _goto;
	}
case 1:
	_match: do {
	_keys = _ImplicitScanner_key_offsets[cs];
	_trans = _ImplicitScanner_index_offsets[cs];
	_klen = _ImplicitScanner_single_lengths[cs];
	if ( _klen > 0 ) {
		int _lower = _keys;
		int _mid;
		int _upper = _keys + _klen - 1;
		while (true) {
			if ( _upper < _lower )
				break;

			_mid = _lower + ((_upper-_lower) >> 1);
			if ( data[p] < _ImplicitScanner_trans_keys[_mid] )
				_upper = _mid - 1;
			else if ( data[p] > _ImplicitScanner_trans_keys[_mid] )
				_lower = _mid + 1;
			else {
				_trans += (_mid - _keys);
				break _match;
			}
		}
		_keys += _klen;
		_trans += _klen;
	}

	_klen = _ImplicitScanner_range_lengths[cs];
	if ( _klen > 0 ) {
		int _lower = _keys;
		int _mid;
		int _upper = _keys + (_klen<<1) - 2;
		while (true) {
			if ( _upper < _lower )
				break;

			_mid = _lower + (((_upper-_lower) >> 1) & ~1);
			if ( data[p] < _ImplicitScanner_trans_keys[_mid] )
				_upper = _mid - 2;
			else if ( data[p] > _ImplicitScanner_trans_keys[_mid+1] )
				_lower = _mid + 2;
			else {
				_trans += ((_mid - _keys)>>1);
				break _match;
			}
		}
		_trans += _klen;
	}
	} while (false);

	_trans = _ImplicitScanner_indicies[_trans];
	cs = _ImplicitScanner_trans_targs[_trans];

case 2:
	if ( cs == 0 ) {
		_goto_targ = 5;
		continue _goto;
	}
	if ( ++p != pe ) {
		_goto_targ = 1;
		continue _goto;
	}
case 4:
	if ( p == eof )
	{
	int __acts = _ImplicitScanner_eof_actions[cs];
	int __nacts = (int) _ImplicitScanner_actions[__acts++];
	while ( __nacts-- > 0 ) {
		switch ( _ImplicitScanner_actions[__acts++] ) {
	case 0:
// line 56 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "null";}
	break;
	case 1:
// line 57 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "bool#yes";}
	break;
	case 2:
// line 58 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "bool#no";}
	break;
	case 3:
// line 59 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "int#hex";}
	break;
	case 4:
// line 60 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "int#oct";}
	break;
	case 5:
// line 61 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "int#base60";}
	break;
	case 6:
// line 62 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "int";}
	break;
	case 7:
// line 63 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "float#fix";}
	break;
	case 8:
// line 64 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "float#exp";}
	break;
	case 9:
// line 65 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "float#base60";}
	break;
	case 10:
// line 66 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "float#inf";}
	break;
	case 11:
// line 67 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "float#neginf";}
	break;
	case 12:
// line 68 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "float#nan";}
	break;
	case 13:
// line 69 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "timestamp#ymd";}
	break;
	case 14:
// line 70 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "timestamp#iso8601";}
	break;
	case 15:
// line 71 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "timestamp#spaced";}
	break;
	case 16:
// line 72 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "timestamp";}
	break;
	case 17:
// line 73 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "default";}
	break;
	case 18:
// line 74 "src/main/org/yecht/ImplicitScanner2.rl"
	{tag = "merge";}
	break;
// line 489 "src/main/org/yecht/ImplicitScanner2.java"
		}
	}
	}

case 5:
	}
	break; }
	}
// line 106 "src/main/org/yecht/ImplicitScanner2.rl"

       return tag;
    }
911165
public static boolean regexMatch(String input, String regex) {
        return Pattern.compile(regex).matcher(input).matches();
    }
452956
private boolean matchNoAsterisk(String toMatch, String subpattern) {

		if (logger.isLoggable(Level.FINEST)) {
			logger.finest("Entering matchNoAsterisk with  toMatch = " + toMatch + " and subpattern = " + subpattern);
		}			

		int toMatchLen = toMatch.length();
		int subpatternLen = subpattern.length();

		if (toMatchLen != subpatternLen) {
			if (logger.isLoggable(Level.FINEST)) {
				logger.finest("FAIL: in matchNoAsterisk:  toMatchLen = " + toMatchLen + " != subpatternLen = " + subpatternLen);
			}			
			return false;
		}

		for (int i = 0; i < toMatchLen; i++) {
			if (subpattern.substring(i,i+1).equals("*")) {
				logger.fine("FAIL: in matchNoAsterisk: Shouldn't have encountered a '*' in matchNoAsterisk, toMatch = " + toMatch + ", subPattern = " + subpattern);
				throw new IllegalStateException("Shouldn't have encountered a '*' in matchNoAsterisk, toMatch = " + toMatch + ", subPattern = " + subpattern);
			} else if (subpattern.substring(i,i+1).equals("?")) {
				// Nothing needed) 
			} else {
				if (subpattern.charAt(i) != toMatch.charAt(i)) {
					if (logger.isLoggable(Level.FINEST)) {
						logger.finest("FAIL: in matchNoAsterisk: mismatch at index: " + i + ". The char subpattern.charAt(i)= "  + subpattern.charAt(i) + " != toMatch.charAt(i) = " + toMatch.charAt(i));
					}			
					return false;
				}			
				// else continue
			}
		}

		if (logger.isLoggable(Level.FINEST)) {
			logger.finest("SUCCESS: in matchNoAsterisk");
		}			

		return true;
	}
767865
public static boolean matches(String pattern, String value) {
        Pattern p = Pattern.compile(pattern);
        Matcher m = p.matcher(value);
        return m.matches();
    }
262452
@Override
    public void promptMatches(String expectedPromptPattern) {
        String prompt = checkPromptMatches(expectedPromptPattern, 0, 0);
        assertTrue("Prompt Text Mismatch: prompt text of '" + prompt + DOES_NOT_MATCH_PATTERN + expectedPromptPattern + "'", prompt.matches(expectedPromptPattern));
    }
1157682
public static Object indexOf(String strPattern, String strInput, int offset, boolean caseSensitive, boolean matchAll) throws MalformedPatternException {
	// Perl5Compiler compiler = new Perl5Compiler();
	PatternMatcherInput input = new PatternMatcherInput(strInput);
	Perl5Matcher matcher = new Perl5Matcher();

	int compileOptions = caseSensitive ? 0 : Perl5Compiler.CASE_INSENSITIVE_MASK;
	compileOptions += Perl5Compiler.SINGLELINE_MASK;
	if (offset < 1) offset = 1;

	Pattern pattern = getPattern(strPattern, compileOptions);
	// Pattern pattern = compiler.compile(strPattern,compileOptions);

	if (offset <= strInput.length()) input.setCurrentOffset(offset - 1);

	if (offset <= strInput.length()) {
	    Array matches = new ArrayImpl();
	    while (matcher.contains(input, pattern)) {
		int match = matcher.getMatch().beginOffset(0) + 1;
		if (!matchAll) {
		    return new Double(match);
		}

		matches.appendEL(match);
	    }

	    if (matches.size() != 0) {
		return matches;
	    }
	}
	return 0;
    }
214244
static boolean matchForward(char[] chars, char[] pattern, int[] cursor) {
    if (pattern.length > cursor[1] - cursor[0])
      return false;
    int index = 0;
    while (index < pattern.length)
      if (chars[cursor[0]++] != pattern[index++])
        return false;
    return true;
  }
123520
public CacheKeyBuilder appendStringsIgnoringOrder(Collection<String> input)
  {
    appendItem(STRING_LIST_KEY, stringCollectionToByteArray(input, false));
    return this;
  }