Process the text so that it will render with a combination of fonts
if needed.
@param text the text
@return a <CODE>Phrase</CODE> with one or more chunks
761676
public Phrase process(String text) {
        int fsize = fonts.size();
        if (fsize == 0)
            throw new IndexOutOfBoundsException("No font is defined.");
        char cc[] = text.toCharArray();
        int len = cc.length;
        StringBuffer sb = new StringBuffer();
        Font font = null;
        int lastidx = -1;
        Phrase ret = new Phrase();
        for (int k = 0; k < len; ++k) {
            char c = cc[k];
            if (c == '\n' || c == '\r') {
                sb.append(c);
                continue;
            }
            if (Utilities.isSurrogatePair(cc, k)) {
                int u = Utilities.convertToUtf32(cc, k);
                for (int f = 0; f < fsize; ++f) {
                    font = (Font)fonts.get(f);
                    if (font.getBaseFont().charExists(u)) {
                        if (lastidx != f) {
                            if (sb.length() > 0 && lastidx != -1) {
                                Chunk ck = new Chunk(sb.toString(), (Font)fonts.get(lastidx));
                                ret.add(ck);
                                sb.setLength(0);
                            }
                            lastidx = f;
                        }
                        sb.append(c);
                        sb.append(cc[++k]);
                        break;
                    }
                }
            }
            else {
                for (int f = 0; f < fsize; ++f) {
                    font = (Font)fonts.get(f);
                    if (font.getBaseFont().charExists(c)) {
                        if (lastidx != f) {
                            if (sb.length() > 0 && lastidx != -1) {
                                Chunk ck = new Chunk(sb.toString(), (Font)fonts.get(lastidx));
                                ret.add(ck);
                                sb.setLength(0);
                            }
                            lastidx = f;
                        }
                        sb.append(c);
                        break;
                    }
                }
            }
        }
        if (sb.length() > 0) {
            Chunk ck = new Chunk(sb.toString(), (Font)fonts.get(lastidx == -1 ? 0 : lastidx));
            ret.add(ck);
        }
        return ret;
    }
1343442
public Span trim(final CharSequence text) {

    int newStartOffset = getStart();

    for (int i = getStart(); i < getEnd()
        && StringUtil.isWhitespace(text.charAt(i)); i++) {
      newStartOffset++;
    }

    int newEndOffset = getEnd();
    for (int i = getEnd(); i > getStart()
        && StringUtil.isWhitespace(text.charAt(i - 1)); i--) {
      newEndOffset--;
    }

    if (newStartOffset == getStart() && newEndOffset == getEnd()) {
      return this;
    } else if (newStartOffset > newEndOffset) {
      return new Span(getStart(), getStart(), getType());
    } else {
      return new Span(newStartOffset, newEndOffset, getType());
    }
  }
643300
public String match(CharSequence text)
    {
        try
        {
            if (text.length() == 0)
            {
                if (acceptEmpty)
                {
                    return "";
                }
                else
                {
                    throw new SyntaxErrorException("empty string not accepted");
                }
            }
            InputReader reader = Input.getInstance(text);
            int rc = match(reader);
            if (rc == 1 && reader.read() == -1)
            {
                return reader.getString();
            }
            else
            {
                throw new SyntaxErrorException("syntax error"
                        + "\n"
                        + reader.getLineNumber() + ": " + reader.getLine()
                        + "\n"
                        + pointer(reader.getColumnNumber() + 2));
            }
        }
        catch (IOException ex)
        {
            throw new IllegalArgumentException("can't happen");
        }
    }
1112353
public void showText (final String text) throws IOException
  {
    if (!inTextMode)
    {
      throw new IllegalStateException ("Must call beginText() before showText()");
    }

    if (fontStack.isEmpty ())
    {
      throw new IllegalStateException ("Must call setFont() before showText()");
    }

    final PDFont font = fontStack.peek ();

    // Unicode code points to keep when subsetting
    if (font.willBeSubset ())
    {
      for (int offset = 0; offset < text.length ();)
      {
        final int codePoint = text.codePointAt (offset);
        font.addToSubset (codePoint);
        offset += Character.charCount (codePoint);
      }
    }

    COSWriter.writeString (font.encode (text), m_aOS);
    write ((byte) ' ');
    writeOperator ((byte) 'T', (byte) 'j');
  }
248109
private static String buildText(String text) {
    // <JAR><JAR> to PARAGRAPH mark in unicode
    text = doubleLineBreak.matcher(text).replaceAll(PARAGRAPH);
    // <JAR> to " "
    text = lineBreak.matcher(text).replaceAll(" ");
    return text;
  }
1064245
public Element text(String text) {
        Validate.notNull(text);

        empty();
        TextNode textNode = new TextNode(text);
        appendChild(textNode);

        return this;
    }
547958
public static String hexHtmlify(String text) {
		String emojifiedStr = emojify(text);
		return htmlifyHelper(emojifiedStr, true, false);
	}
250200
static Text asEngineText(final IText text) {
        if (text instanceof Text) {
            return (Text) text;
        }
        return new Text(text.getText(), text.getTemplateName(), text.getLine(), text.getCol());
    }
1061524
public synchronized void setText(String text) {
        setLines(splitIntoMultipleLines(text));
        this.labelSize = getBounds(lines, labelSize);
        invalidate();
    }
17275
public final String transliterate(String text) {
        ReplaceableString result = new ReplaceableString(text);
        transliterate(result);
        return result.toString();
    }
1334514
public void append(final Object text) {
		if (text instanceof Message) {
			append(translate(text), true);
		} else if (text != null) {
			append(text.toString(), true);
		}
	}
1011297
public static String[] simpleTokenize(String text) {
		if (GeneralUtils.isEmpty(text))
			return null;
		return text.split("[ ,.;:><^`�\\]\\[}{|��+_)(*&�%$#@!=\\-?�\\/\"]+", -1);
	}
463878
public TextBuilder parStyledContent(final String text, final TextStyle ts) {
        return this.par().styledSpan(text, ts);
    }
1367489
public static String capitalize( String text )
    {
        if (text == null || text.length() == 0)
            return text;
        
        if (Character.isLowerCase(text.charAt(0)))
            return Character.toUpperCase(text.charAt(0)) + text.substring(1);
        else
            return text;
    }
257255
public List<Mistake> checkText(String text) {
    List<Mistake> mistakes = null;
    try {
      mistakes = analyseAndCheckText(text).mistakes;
    } catch (IndexOutOfBoundsException e) {
      LOGGER.fatal("Failed to process text: " + text, e);
      throw new RuntimeException(e);
    }
    return mistakes;

  }
312471
public static List<Sentence> splitSentences(CharSequence text) {
    return JavaConversions.seqAsJavaList(
        TwitterKoreanProcessor.splitSentences(text)
    );
  }
1345583
@SuppressWarnings("MethodMayBeStatic")
    public NerResultSet process(final String _text) {
        // tokenization
        final List<List<Token>> tokens = TOKENIZER.process(_text);
        // extract name phrase:
        final List<List<Phrase>> phrases = new ArrayList<>();

        for (final List<Token> tokenList : tokens) {
            // for each sentence
            final List<Phrase> sentencePhrase = new ArrayList<>();
            int wordPtr = 0;
            int phraseStubStartPtr = 0;
            while (wordPtr < tokenList.size()) {

                // iterate through every words in the sentence
                final List<Token> currentPhrase = new ArrayList<>();

                // get the phrase stub
                while (true) {
                    // we merge the names combined with the word 'and'
                    // if the second phrase is much shorter than the first phrase
                    // example: Canberra Institution of Science and Technology
                    boolean mergeAndFlag = false;
                    if ("and".equalsIgnoreCase(tokenList.get(wordPtr).text)
                        && !currentPhrase.isEmpty()
                        && wordPtr + 1 < tokenList.size()
                        && detectNameWordInSentenceByPosition(tokenList, wordPtr + 1)) {
                        if (wordPtr + currentPhrase.size() - 1 >= tokenList.size()) {
                            mergeAndFlag = true;
                        }
                        else {
                            for (int i = wordPtr + 1; i <= wordPtr + currentPhrase.size() - 1; i++) {
                                if (!detectNameWordInSentenceByPosition(tokenList, i)) {
                                    mergeAndFlag = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (detectNameWordInSentenceByPosition(tokenList, wordPtr)
                        || (equalsIgnoreCase(tokenList.get(wordPtr).text, "of", "the", "'s")
                            && !currentPhrase.isEmpty()
                            && wordPtr + 1 < tokenList.size()
                            && detectNameWordInSentenceByPosition(tokenList, wordPtr + 1))
                        || mergeAndFlag) {
                        if (currentPhrase.isEmpty()) phraseStubStartPtr = wordPtr; // record the index of the first word
                        currentPhrase.add(tokenList.get(wordPtr));
                        wordPtr++;
                        if (wordPtr == tokenList.size()) break;
                    }
                    else break;
                }

                //get the attached 'the' or 'a'
                int phrasePos = phraseStubStartPtr;
                int phraseLen = currentPhrase.size();

                // if phrasePos is zero, then it is the first word, there won't be any 'the' or 'a' attached to this word.
                if (phrasePos > 0) {
                    final Token attachedArticle = tokenList.get(phrasePos - 1);
                    if ("the".equalsIgnoreCase(attachedArticle.text) || "a".equalsIgnoreCase(attachedArticle.text)) {
                        phrasePos--;
                        phraseLen++;
                    }
                }

                //handling non-name single words such as: Monday, January, etc.
                if (currentPhrase.size() == 1 && phraseStubStartPtr == phrasePos) {
                    if (NON_NAME_WORDS.contains(currentPhrase.get(0).text)) {
                        currentPhrase.clear();
                        wordPtr--;
                    }
                }

                if (currentPhrase.isEmpty()) {
                    // if the current pointed word is not a name phrase
                    // ESTIMATE IF IT IS A TIME/DATE
                    final List<Token> currentDatePhrase = new ArrayList<>();
                    final DatePhraseModel dpm = new DatePhraseModel();
                    int tempPtr = wordPtr;
                    while (true) {
                        final Token word = tokenList.get(tempPtr);
                        final DateType type = getDateType(word.text);
                        if (type != NONE
                            || equalsIgnoreCase(word.text, "of", ",", "the")
                               && !currentDatePhrase.isEmpty()
                               && tempPtr + 1 != tokenList.size()
                               && getDateType(tokenList.get(tempPtr + 1).text) != NONE
                               && getDateType(tokenList.get(tempPtr - 1).text) != NONE) {
                            // is date word:
                            currentDatePhrase.add(word);
                            dpm.addType(type);
                            tempPtr++;
                            if (tempPtr == tokenList.size()) break;
                        }
                        else break;
                    }
                    if (dpm.isDate()) {
                        // add the phrase to phrase array
                        sentencePhrase.add(new Date(currentDatePhrase, wordPtr, currentDatePhrase.size(), wordPtr));
                        wordPtr = tempPtr;
                    }
                }
                else if (!(currentPhrase.size() == 1
                           && (isPastTense(currentPhrase.get(0).text) || isPlural(currentPhrase.get(0).text)))) {
                    sentencePhrase.add(new Name(currentPhrase, phrasePos, phraseLen, phraseStubStartPtr));
                }

                wordPtr++;
            }

            phrases.add(sentencePhrase);
        }

        // find attached words(preps):
        for (int si = 0; si < tokens.size(); si++) {
            final List<Token> sentenceToken = tokens.get(si);
            final List<Phrase> sentencePhrase = phrases.get(si);
            for (int pi = 0; pi < sentencePhrase.size(); pi++) {
                getAttachedPrep(sentenceToken, sentencePhrase, pi);
            }
        }

        return new NerResultSet(phrases, tokens);
    }