Convert the list of format, string tokens to pairs of (format, string)
 except for the first string fragment which doesn't require a default
 formatting run. Use the default for strings without a leading format.
193221
def rich_strings_fragments(rich_strings) # :nodoc:
      # Create a temp format with the default font for unformatted fragments.
      default = Format.new(0)

      length = 0                     # String length.
      last = 'format'
      pos  = 0

      fragments = []
      rich_strings.each do |token|
        if token.respond_to?(:xf_index)
          # Can't allow 2 formats in a row
          return nil if last == 'format' && pos > 0

          # Token is a format object. Add it to the fragment list.
          fragments << token
          last = 'format'
        else
          # Token is a string.
          if last != 'format'
            # If previous token wasn't a format add one before the string.
            fragments << default << token
          else
            # If previous token was a format just add the string.
            fragments << token
          end

          length += token.size    # Keep track of actual string length.
          last = 'string'
        end
        pos += 1
      end
      [fragments, length]
    end
65893
def format_string(string_to_format, wordstyle="lowercase", separator=" "):
    
    # first split the string up into its constituent words
    words = string_to_format.split(" ")

    # format the individual words
    function_map = {
        "lowercase": format_word_list_lowercase,
        "uppercase": format_word_list_uppercase,
        "capitalize": format_word_list_capitalize,
        "mixedcase": format_word_list_mixedcase
    }

    try:
        words = function_map[wordstyle](words)
    except KeyError:
        msg = "Passed in an invalid wordstyle, allowed styles are {}"
        raise InvalidWordStyleError(msg.format(function_map.keys()))

    # now add in the separator and return
    return str(separator).join(words)
1268135
private FormatString[] parse(String s) {
        ArrayList<FormatString> al = new ArrayList<>();
        for (int i = 0, len = s.length(); i < len; ) {
            int nextPercent = s.indexOf('%', i);
            if (s.charAt(i) != '%') {
                // This is plain-text part, find the maximal plain-text
                // sequence and store it.
                int plainTextStart = i;
                int plainTextEnd = (nextPercent == -1) ? len: nextPercent;
                al.add(new FixedString(s.substring(plainTextStart,
                                                   plainTextEnd)));
                i = plainTextEnd;
            } else {
                // We have a format specifier
                FormatSpecifierParser fsp = new FormatSpecifierParser(s, i + 1);
                al.add(fsp.getFormatSpecifier());
                i = fsp.getEndIdx();
            }
        }
        return al.toArray(new FormatString[al.size()]);
    }
424112
def complete_opt_format(self, text, *_):
        
        return [t + " " for t in FORMATTERS if t.startswith(text)]
759915
def tags_check_convert(cls, tags):
        
        # single string check comes first since string is also a Sequence
        if isinstance(tags, string_types):
            return [cls.__tag_check_convert(tags)]
        elif isinstance(tags, Sequence):
            if not tags:
                raise ValueError("Tag list is empty")
            return [cls.__tag_check_convert(tag) for tag in tags]
        else:
            raise ValueError("tags must be a single string or list of sequence of strings")
1100280
private ArrayList<ArrayList<String>> parseString(String text) {

        ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
        StringTokenizer linetoken = new StringTokenizer(text, "\n");
        StringTokenizer token;
        String current;
        while (linetoken.hasMoreTokens()) {
            current = linetoken.nextToken();
            if (current.contains(",")) {
                token = new StringTokenizer(current, ",");
            } else {
                token = new StringTokenizer(current);
            }
            ArrayList<String> line = new ArrayList<String>();
            while (token.hasMoreTokens()) {
                line.add(token.nextToken());
            }
            result.add(line);
        }
        return result;
    }
899146
def tokenize(self, s):
    """"""
    s = tf.compat.as_text(s)

    if self.reserved_tokens:
      # First split out the reserved tokens
      substrs = self._reserved_tokens_re.split(s)
    else:
      substrs = [s]

    toks = []
    for substr in substrs:
      if substr in self.reserved_tokens:
        toks.append(substr)
      else:
        toks.extend(self._alphanum_re.split(substr))

    # Filter out empty strings
    toks = [t for t in toks if t]
    return toks
1145959
private String listToString(List<String> stringList){
		StringBuilder concat = new StringBuilder();
		for(String str:stringList){
			concat.append(str);
			concat.append(System.getProperty("line.separator"));
		}
		return concat.toString();
	}
521374
def format_string_values(obj, err_fallback=(IndexError, KeyError), *args, **kwargs):
    
    if isinstance(obj, dict):
        new = {}
        for key in obj.keys():
            new[key] = format_string_values(obj[key], *args, **kwargs)
        return new
    elif isinstance(obj, list):
        new = []
        for item in obj:
            new.append(format_string_values(item, *args, **kwargs))
        return new
    elif isinstance(obj, six.string_types):
        try:
            return obj.format(*args, **kwargs)
        except err_fallback:
            return obj
    else:
        return obj
477800
def split_mapping(pair_str):
    
    orig_key, value = pair_str.split("=", 1)
    key = orig_key.strip()
    if key != orig_key:
        warnings.warn(
            "Mapping key {} has leading or trailing space".format(repr(orig_key)),
            LeadingTrailingSpaceInKey,
        )
    return key, value
202070
def Plural(format_str):
  
  if format_str.startswith('plural?'):
    i = len('plural?')

    try:
      splitchar = format_str[i]  # Usually a space, but could be something else
      _, plural_val, singular_val = format_str.split(splitchar)
    except IndexError:
      raise Error('plural? must have exactly 2 arguments')

    def Formatter(value):
      plural = False
      if isinstance(value, int) and value > 1:
        plural = True
      if isinstance(value, list) and len(value) > 1:
        plural = True

      if plural:
        return plural_val
      else:
        return singular_val

    return Formatter

  else:
    return None
378761
function getFormatStringFrom (formattedString) {
      var chunks = formattedString.match(R_FORMAT_CHUNKS);

      if (!chunks) {
        // chunks will be null if there were no tokens to parse in
        // formattedString (for example, if formattedString is '2').  Coerce
        // chunks to be useful here.
        chunks = ['', ''];

        // If there is only one chunk, assume that the string is a number
        // followed by a token...
        // NOTE: This may be an unwise assumption.
      } else if (chunks.length === 1 ||
          // ...or if the string starts with a number component (".", "-", or a
          // digit)...
          formattedString[0].match(R_NUMBER_COMPONENT)) {
        // ...prepend an empty string here to make sure that the formatted number
        // is properly replaced by VALUE_PLACEHOLDER
        chunks.unshift('');
      }

      return chunks.join(VALUE_PLACEHOLDER);
    }
636490
def sort_string_by_pairs(strings):
    """"""
    assert len(strings) % 2 == 0
    pairs = []
    strings = list(strings) # This shallow copies the list
    while strings:
        template = strings.pop()
        for i, candidate in enumerate(strings):
            if count_string_diff(template, candidate) == 1:
                pair = [template, strings.pop(i)]
                pair.sort()
                pairs.append(pair)
                break
    return pairs
657064
def to_list(stringlist, unquote=True):
    """"""
    stringlist = stringlist[1:-1]
    return [
        string.strip('"') if unquote else string
        for string in stringlist.split(",")
    ]
444354
def process_format(self, kind, context):
		""""""
		
		result = None
		
		while True:
			chunk = yield result
			
			if chunk is None:
				return
			
			# We need to split the expression defining the format string from the values to pass when formatting.
			# We want to allow any Python expression, so we'll need to piggyback on Python's own parser in order
			# to exploit the currently available syntax.  Apologies, this is probably the scariest thing in here.
			split = -1
			line = chunk.line
			
			try:
				ast.parse(line)
			except SyntaxError as e:  # We expect this, and catch it.  It'll have exploded after the first expr.
				split = line.rfind(' ', 0, e.offset)
			
			result = chunk.clone(line='_bless(' + line[:split].rstrip() + ').format(' + line[split:].lstrip() + ')')
315095
public CharSequence format() {
    if (formatted == null) {
      if (!keysToValues.keySet().containsAll(keys)) {
        Set<String> missingKeys = new HashSet<String>(keys);
        missingKeys.removeAll(keysToValues.keySet());
        throw new IllegalArgumentException("Missing keys: " + missingKeys);
      }

      // Copy the original pattern to preserve all spans, such as bold, italic, etc.
      SpannableStringBuilder sb = new SpannableStringBuilder(pattern);
      for (Token t = head; t != null; t = t.next) {
        t.expand(sb, keysToValues);
      }

      formatted = sb;
    }
    return formatted;
  }
748434
def join(strings: Optional[Sequence[str]], separator: str = "") -> str:
    
    return separator.join(s for s in strings if s) if strings else ""