Returns the string before the given token

@param text  the text
@param before the token
@return the text before the token, or <tt>null</tt> if text does not contain the token
165572
public static String before(String text, String before) {
        if (!text.contains(before)) {
            return null;
        }
        return text.substring(0, text.indexOf(before));
    }
1195583
@javax.annotation.Nonnull
  public static String getIndent(@javax.annotation.Nonnull final String txt) {
    @javax.annotation.Nonnull final Matcher matcher = Pattern.compile("^\\s+").matcher(txt);
    return matcher.find() ? matcher.group(0) : "";
  }
222016
public T find(String text)
    {
        T match = matcher.match(text, true);
        if (match != null)
        {
            String name = match.name();
            if (name.substring(0, Math.min(name.length(), text.length())).equalsIgnoreCase(text))
            {
                return match;
            }
        }
        return null;
    }
370943
private Ctx findContext( String text ) {

		// Are we inside a comment?
		Ctx ctx = new Ctx();
		int n;
		for( n = text.length() - 1; n >= 0; n-- ) {
			char c = text.charAt( n );
			if( isLineBreak( c ))
				break;

			if( c == '#' ) {
				ctx.kind = CtxKind.COMMENT;
				return ctx;
			}
		}

		// Simplify the search: remove all the comments.
		text = TextUtils.removeComments( text );

		// Keep on simplifying the search: remove complete instances
		// Since instances can contain other instances (recursivity), we must
		// apply the pattern several times, until no more replacement is possible.
		int before = -1;
		int after = -2;
		while( before != after ) {
			before = text.length();
			text = text.replaceAll( "(?i)(?s)instance\\s+of[^{]*\\{[^{}]*\\}", "" );
			after = text.length();
		}

		// Remove white spaces at the beginning of the string.
		text = text.replaceAll( "^(\n|\r\n)+", "" );

		// Now, find our context.
		String lastWord = null, lastLine = null;
		StringBuilder sb = new StringBuilder();

		for( n = text.length() - 1; n >= 0 && ctx.kind == CtxKind.NEUTRAL; n-- ) {
			char c = text.charAt( n );

			// After a "colon" => we are in a property, forget it...
			if( c == ':' && lastWord != null ) {
				ctx.kind = CtxKind.ATTRIBUTE_VALUE;
				break;
			}

			// White space? We have a our last word.
			if( Character.isWhitespace( c ) && lastWord == null )
				lastWord = sb.toString();

			// Store the last line.
			if( isLineBreak( c ) && lastLine == null )
				lastLine = sb.toString();

			// After a semicolon: we should suggest new attributes
			if( c == ';' )
				ctx.kind = CtxKind.ATTRIBUTE;

			// Same thing after a curly bracket
			else if( c == '{' )
				ctx.kind = CtxKind.ATTRIBUTE;

			else {
				sb.insert( 0, c );
				String cmp = sb.toString();
				if( lastWord != null )
					cmp = cmp.substring( 0, cmp.length() - lastWord.length());

				cmp = cmp.trim().replaceAll( "\\s{2,}", " " );
				if( cmp.equals( KEYWORD_INSTANCE_OF ))
					ctx.kind = CtxKind.COMPONENT_NAME;

				else if( cmp.equals( KEYWORD_IMPORT )
						&& ! sb.toString().matches( ".*" + KEYWORD_IMPORT ))
					ctx.kind = CtxKind.IMPORT;
			}
		}

		// Update the context
		ctx.lastWord = lastWord == null ? sb.toString() : lastWord;

		// If we are in the attribute state, we should verify the last line.
		// Case "instance of C " would otherwise indicate
		if( lastLine == null )
			lastLine = sb.toString();

		if( lastLine.matches( "(?i).*\\binstance\\s+of\\s+\\S+\\s+" )) {
			ctx.kind = CtxKind.NOTHING;
		}

		// Find the parent instance (which is the first declared instance at the end of 'text').
		Pattern p = Pattern.compile( "(?i)([\\t ]*)instance\\s+of\\s+([^{]+)", Pattern.CASE_INSENSITIVE );
		Matcher m = p.matcher( text );
		while( m.find()) {
			// instance of t| => 'lastWord == t' and 'm.group( 2 ) == t''
			// instance of => 'lastWord' is not relevant...
			if( ! Objects.equals( ctx.lastWord, m.group( 2 ).trim())) {
				ctx.parentIndentation = m.group( 1 );
				ctx.parentIndentation += "\t";
				ctx.parentInstanceType = m.group( 2 ).trim();
			}
		}

		return ctx;
	}
210247
@Override
  public List<String> tokenize(final String text) {
    final List<String> l = new ArrayList<>();
    final StringTokenizer st = new StringTokenizer(text, nlTokenizingChars, true);
    while (st.hasMoreElements()) {
      String token = st.nextToken();
      String origToken = token;
      if (token.length() > 1) {
        if (startsWithQuote(token) && endsWithQuote(token) && token.length() > 2) {
          l.add(token.substring(0, 1));
          l.add(token.substring(1, token.length()-1));
          l.add(token.substring(token.length()-1, token.length()));
        } else if (endsWithQuote(token)) {
          int cnt = 0;
          while (endsWithQuote(token)) {
            token = token.substring(0, token.length() - 1);
            cnt++;
          }
          l.add(token);
          for (int i = origToken.length() - cnt; i < origToken.length(); i++) {
            l.add(origToken.substring(i, i + 1));
          }
        } else if (startsWithQuote(token)) {
          while (startsWithQuote(token)) {
            l.add(token.substring(0, 1));
            token = token.substring(1, token.length());
          }
          l.add(token);
        } else {
          l.add(token);
        }
      } else {
        l.add(token);
      }
    }
    return joinEMailsAndUrls(l);
  }
30424
public CharSequence getCoveredText(CharSequence text) {
    if (getEnd() > text.length()) {
      throw new IllegalArgumentException("The span " + toString()
          + " is outside the given text!");
    }

    return text.subSequence(getStart(), getEnd());
  }
514366
public synchronized List<Token> tokens(String text) {
        requireValidHandle();
        List<Token> allTokens = new ArrayList<Token>();
        int lastStart = 0;
        for (int i = indexOfSpecialUnknown(text, 0); i != -1; i = indexOfSpecialUnknown(text, i + 1)) {
            allTokens.addAll(tokensNonNull(text.substring(lastStart, i), lastStart));
            allTokens.add(new Token(TokenType.UNKNOWN, Character.toString(text.charAt(i)), i));
            lastStart = i + 1;
        }
        allTokens.addAll(tokensNonNull(text.substring(lastStart), lastStart));
        return allTokens;
    }
1159578
@Pure
	public static char getMnemonicChar(String text) {
		if (text != null) {
			final int pos = text.indexOf('&');
			if ((pos != -1) && (pos < text.length() - 1)) {
				return text.charAt(pos + 1);
			}
		}
		return '\0';
	}
779713
public boolean textPresent(String expectedText) {
        try {
            String bodyText = driver.findElement(By.tagName("body")).getText();
            return bodyText.contains(expectedText);
        } catch (Exception e) {
            log.info(e);
            return false;
        }
    }
608787
public T text(CharSequence text, boolean goneIfEmpty) {

        if (goneIfEmpty && (text == null || text.length() == 0)) {
            return gone();
        } else {
            return text(text);
        }
    }
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;
    }
1221172
public List<String> tokenize(String text) {
		List<String> tokens = new ArrayList<String>();
		text = text.toLowerCase();
		char[] array = text.toCharArray();
		
		//convert all apostrophes to 0x27
		for(int i = 0; i < array.length; i++) {
			if(isApostrofe(array[i])) array[i] = 0x27;
		}
		
		int pos = 0;
		
		//term cycle
		while(pos < array.length) {
			//scan to the start of the term
			while(pos < array.length  && !Character.isLetterOrDigit(array[pos])) pos++;
			int start = pos;
			if(start == array.length) break;
			//scan to the end of the term
			while(pos < array.length  && isLetterOrDigitOrApostrofe(array[pos])) pos++;
			int newpos = pos;
			while(newpos > start && isApostrofe(array[newpos - 1])) newpos--;
			if(newpos > start) tokens.add(new String(array, start, newpos - start));
		}
		return tokens;
	}
1011297
public static String[] simpleTokenize(String text) {
		if (GeneralUtils.isEmpty(text))
			return null;
		return text.split("[ ,.;:><^`�\\]\\[}{|��+_)(*&�%$#@!=\\-?�\\/\"]+", -1);
	}
650127
public void showText(PdfTextArray text) {
        if (state.fontDetails == null)
            throw new NullPointerException("Font and size must be set before writing any text");
        content.append("[");
        ArrayList arrayList = text.getArrayList();
        boolean lastWasNumber = false;
        for (int k = 0; k < arrayList.size(); ++k) {
            Object obj = arrayList.get(k);
            if (obj instanceof String) {
                showText2((String)obj);
                lastWasNumber = false;
            }
            else {
                if (lastWasNumber)
                    content.append(' ');
                else
                    lastWasNumber = true;
                content.append(((Float)obj).floatValue());
            }
        }
        content.append("]TJ").append_i(separator);
    }
557679
public boolean hasStopWord(HString text) {
    if (text == null) {
      return true;
    } else if (text.isInstance(Types.TOKEN)) {
      return isTokenStopWord(Cast.as(text));
    }
    return text.tokens().stream().anyMatch(this::isTokenStopWord);
  }
586503
public static String substringBefore(String text, char stopper) {
        int p = text.indexOf(stopper);
        return p < 0 ? text : text.substring(0, p);
    }
900248
public List<List<Token>> process(final String text) {
        final List<List<Token>> paragraph = new ArrayList<>();
        currentSentence = new ArrayList<>();
        final Tokens tokens = splitText(text);

        while (tokens.hasNext()) {
            final Token t = tokens.next();
            final String trimmedWord = t.text.trim();

            // skip spaces
            if (trimmedWord.isEmpty()) continue;

            if (((mode == WITH_PUNCTUATION) || (mode == WITHOUT_PUNCTUATION && isLetterOrDigit(initChar(t.text))))) {
                boolean canBreakSentence = true;
                if (t.text.contains("'")) {
                    wordContainsApostrophe(t);
                }
                else if (".".equals(trimmedWord)) {
                    canBreakSentence = wordIsFullStop(t);
                }
                else if (":".equals(trimmedWord)) {
                    wordIsColon(tokens, t);
                }
                else currentSentence.add(t);

                // handling the end of a sentence
                if (canBreakSentence && equalss(trimmedWord, ".", ";", "?", "!")) {
                    paragraph.add(currentSentence);
                    currentSentence = new ArrayList<>();
                }
            }
        }

        if (!currentSentence.isEmpty()) paragraph.add(currentSentence);
        return paragraph;
    }