Returns the Nth occurrence of the specified character in the specified
String, but ignoring those contained in single quotes.
179379
static private int indexOfNthOccurrenceOfCharIn(String str, char ch, int n) {
        boolean inMiddleOfQuote = false;
        int index = -1, previousIndex = 0;
        for (int i=0; i < n; i++) {
            do {
                index = str.indexOf(ch, index+1);
                if (index < 0) {
                    return -1;
                }
                if (hasOddNumberOfSingleQuotes(str.substring(previousIndex, index))) {
                    inMiddleOfQuote = !inMiddleOfQuote;
                }
                previousIndex = index;
            } while (inMiddleOfQuote);
        }
        return index;
    }
591762
private int countNonNewline(String str, int off, int len) {
    for(int cnt = 0; cnt < len; cnt++) {
      final int pos = off + cnt;
      if(str.charAt(pos) == UNIX_NEWLINE) {
        return cnt;
      }
      if(str.charAt(pos) == CARRIAGE_RETURN) {
        return cnt;
      }
    }
    return len;
  }
1352929
function inText(string, n) {
  let firstIndex = string.search(/"|'/);
  if (firstIndex === -1 || firstIndex > n) return false;
  let char = '';
  let last = '';
  for (let i = 0; i < n; i++) {
    let c = string[i];
    if (c === '"' || c === "'") {
      if (!char) {
        char = c;
      } else if (char === c && last !== '\\') {
        char = '';
      }
    }
    last = c;
  }
  return char !== '';
}
728076
public static int countChars(final String str, final char chr) {
        int count = 0;
        boolean isWithinDoubleQuotes = false;
        boolean isWithinQuotes = false;

        for (int i = 0; i < str.length(); i++) {
            final char c = str.charAt(i);
            if (c == '"' && !isWithinQuotes && !isWithinDoubleQuotes) {
                isWithinDoubleQuotes = true;
            } else if (c == '"' && !isWithinQuotes) {
                isWithinDoubleQuotes = false;
            }

            if (c == '\'' && !isWithinQuotes && !isWithinDoubleQuotes) {
                isWithinQuotes = true;
            } else if (c == '\'' && !isWithinDoubleQuotes) {
                isWithinQuotes = false;
            }

            if (!isWithinDoubleQuotes && !isWithinQuotes) {
                if (chr == c) {
                    count++;
                }
            }
        }
        return count;
    }
206254
public static int nthIndex(String s, char ch, int n) {
    int index = 0;
    for (int i = 0; i < n; i++) {
      // if we're already at the end of the string,
      // and we need to find another ch, return -1
      if (index == s.length() - 1) {
        return -1;
      }
      index = s.indexOf(ch, index + 1);
      if (index == -1) {
        return (-1);
      }
    }
    return index;
  }
641887
private static int quoteSingle(final StringBuilder sb, final String string, final int start) {
        int i = start+1;
        if (needsBlockQuoting(string.charAt(start))) return -i;
        int unquoteLen = 0;
        int quotedMap = 1;
        for (int j = 1; i < string.length(); i++, j++) {
            char c = string.charAt(i);
            if (needsQuoting(c)) {
                if (j > MAX_SINGLE_QUOTE_LEN || needsBlockQuoting(c)) return -i-1;
                quotedMap |= 1 << j;
                unquoteLen = 0;
            } else {
                if (unquoteLen == MAX_UNQUOTE_LEN ||
                        (quotedMap == 1 && 
                         unquoteLen == MAX_SINGLE_UNQUOTE_LEN)) {
                    break;
                }
                unquoteLen++;
            }
        }
        appendSingleQuoted(sb, string, start, i - unquoteLen, quotedMap);
        sb.append(string, i - unquoteLen, i);
        return i;
    }
868086
def NonNegIntStringToInt(int_string, problems=None):
  """"""
  # Will raise TypeError unless a string
  match = re.match(r"^(?:0|[1-9]\d*)$", int_string)
  # Will raise ValueError if the string can't be parsed
  parsed_value = int(int_string)

  if parsed_value < 0:
    raise ValueError()
  elif not match and problems is not None:
    # Does not match the regex, but it's an int according to Python
    problems.InvalidNonNegativeIntegerValue(int_string)

  return parsed_value
863760
public static String createQuotedConstant(String str) {
        if (str == null || str.isEmpty()) {
            return str;
        }
        try {
            Double.parseDouble(str);
        } catch (NumberFormatException nfe) {
            return "\"" + str + "\"";
        }
        return str;
    }
797334
def match(self, chars):
        """"""
        start_index = self.next_index
        for char in self:
            if char not in chars:
                self.next_index -= 1
                break
        return self[start_index:self.next_index]
1298294
public static int occurrencesOfChar(String string, final char value)
    {
        return StringIterate.countChar(string, new CharPredicate()
        {
            public boolean accept(char character)
            {
                return value == character;
            }
        });
    }
1162199
public static String getQuotedString(String st) {
    Preconditions.checkNotNull(st);
    String quotedString = "";
    if (!st.startsWith(SINGLE_QUOTE)) {
      quotedString += SINGLE_QUOTE;
    }
    quotedString += st;
    if (!st.endsWith(SINGLE_QUOTE)) {
      quotedString += SINGLE_QUOTE;
    }
    return quotedString;
  }
708853
public String getLeftOf(String srcStr, int charCount) {

        String retValue = "";

        if (isNotBlank(srcStr)) {

            int length = srcStr.length();

            if (charCount < length) {
                retValue = srcStr.substring(0, charCount);
            } else {
                retValue = srcStr;
            }
        }

        return retValue;
    }
1071795
function detectQuote(str) {
	if (str == null || str.length == 0) return false;
	var first = str.charAt(0);
	var last = str.charAt(str.length - 1);
	if (first != last) return false;
	if (first == map.single) return map.single;
	if (first == map.double) return map.double;
	return false;
}
374502
function repeatString(string, nb) {
    var s = string,
        l,
        i;

    if (nb <= 0)
      return '';

    for (i = 1, l = nb | 0; i < l; i++)
      s += string;
    return s;
  }
1095713
def numberize(string):
    ''''''
    if not isinstance(string,basestring):
        return string
    just_int = r'^\s*[-+]?\d+\s*$'
    just_float = r'^\s*[-+]?\d+\.(\d+)?\s*$'
    if re.match(just_int,string):
        return int(string)
    if re.match(just_float,string):
        return float(string)
    return string
631726
static public String removeTrailingNewLines(String string) {
    	if (string == null) return string;
    	
    	String trimmedString = chomp(string);

    	// Loop until the chomp-method does not remove any more trailing NewLines...
    	while (trimmedString.length() < string.length()) {
			// Try remove one more NewLine
    		string = trimmedString;
			trimmedString = chomp(string);
		}
    	
    	return trimmedString;
    	
    }
219197
public static String unquote(String s)
    {
        if (s==null)
            return null;
        if (s.length()<2)
            return s;

        char first=s.charAt(0);
        char last=s.charAt(s.length()-1);
        if (first!=last || (first!='"' && first!='\''))
            return s;

        StringBuilder b=new StringBuilder(s.length()-2);
        boolean escape=false;
        for (int i=1;i<s.length()-1;i++)
        {
            char c = s.charAt(i);

            if (escape)
            {
                escape=false;
                switch (c)
                {
                    case 'n':
                        b.append('\n');
                        break;
                    case 'r':
                        b.append('\r');
                        break;
                    case 't':
                        b.append('\t');
                        break;
                    case 'f':
                        b.append('\f');
                        break;
                    case 'b':
                        b.append('\b');
                        break;
                    case 'u':
                        b.append((char)(
                                (convertHexDigit((byte)s.charAt(i++))<<24)+
                                (convertHexDigit((byte)s.charAt(i++))<<16)+
                                (convertHexDigit((byte)s.charAt(i++))<<8)+
                                (convertHexDigit((byte)s.charAt(i++)))
                                )
                        );
                        break;
                    default:
                        b.append(c);
                }
            }
            else if (c=='\\')
            {
                escape=true;
                continue;
            }
            else
                b.append(c);
        }

        return b.toString();
    }