private EditText text = (EditText)findViewById(R.id.text); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text.setOnKeyListener(new TextMaker()); }
private int wikiWordLength(String candidate) { if (candidate.length() < 3) return 0; if (!isUpperCaseLetter(candidate, 0)) return 0; if (!isDigit(candidate, 1) && !isLowerCaseLetter(candidate, 1)) return 0; int lastUpperCaseLetter = 0; int i; for (i = 2; i < candidate.length(); i++) { if (isCharacter(candidate, '_', i)) return 0; if (isUpperCaseLetter(candidate, i)) { if (i == lastUpperCaseLetter + 1) return 0; lastUpperCaseLetter = i; } else if (!isDigit(candidate, i) && !isLetter(candidate, i) /*&& !isCharacter(candidate, '.', i)*/) break; } if (lastUpperCaseLetter > 0 && i > 2) return i; return 0; }
public int findWikiWordLength(String text) { String candidate = text + "."; int offset = "<>^.".contains(candidate.substring(0, 1)) ? 1 : 0; while (offset < candidate.length()) { int dot = candidate.indexOf(".", offset); int word = wikiWordLength(candidate.substring(offset, dot)); if (word == 0) return offset > 1 ? offset - 1 : 0; if (offset + word < dot) return offset + word; offset = dot + 1; } return text.length(); }
private boolean isLetter(String candidate, int offset) { return isUpperCaseLetter(candidate, offset) || isLowerCaseLetter(candidate, offset); }
public SymbolMatch make(ParseSpecification specification, int offset, String text) { if (specification.matchesFor(WikiWord.symbolType)) { int length = findWikiWordLength(text); if (length > 0) { Symbol wikiWord = new Symbol(new WikiWord(sourcePage), text.substring(0, length), offset); wikiWord.evaluateVariables(new String[]{WikiWord.REGRACE_LINK}, variableSource); return new SymbolMatch(wikiWord, offset, length); } } if (specification.matchesFor(SymbolType.EMail) && isEmailAddress(text)) { return new SymbolMatch(SymbolType.EMail, text, offset); } return new SymbolMatch(SymbolType.Text, text, offset); }
private Step makeNextStep(final ParseSpecification specification, final int startPosition) { input.setOffset(startPosition); int newNext = startPosition; Symbol matchSymbol = null; while (!input.isEnd()) { SymbolMatch match = specification.findMatch(input, startPosition, symbols); if (match.isMatch()) { matchSymbol = match.getSymbol(); newNext = input.getOffset() + match.getMatchLength(); break; } input.moveNext(); } if (input.getOffset() > startPosition) { SymbolMatch match = textMaker.make(specification, startPosition, input.substringFrom(startPosition)); return new Step(match.getSymbol(), startPosition + match.getMatchLength()); } if (input.isEnd()) { return new Step(Symbol.emptySymbol, input.getOffset()); } return new Step(matchSymbol, newNext); }
private boolean isLetter(String candidate, int offset) { return isUpperCaseLetter(candidate, offset) || isLowerCaseLetter(candidate, offset); }
public SymbolMatch make(ParseSpecification specification, int offset, String text) { if (specification.matchesFor(WikiWord.symbolType)) { int length = findWikiWordLength(text); if (length > 0) { Symbol wikiWord = new Symbol(new WikiWord(sourcePage), text.substring(0, length), offset); wikiWord.evaluateVariables(new String[]{WikiWord.REGRACE_LINK}, variableSource); return new SymbolMatch(wikiWord, offset, length); } } if (specification.matchesFor(SymbolType.EMail) && isEmailAddress(text)) { return new SymbolMatch(SymbolType.EMail, text, offset); } return new SymbolMatch(SymbolType.Text, text, offset); }
private Step makeNextStep(final ParseSpecification specification, final int startPosition) { input.setOffset(startPosition); int newNext = startPosition; Symbol matchSymbol = null; while (!input.isEnd()) { SymbolMatch match = specification.findMatch(input, startPosition, symbols); if (match.isMatch()) { matchSymbol = match.getSymbol(); newNext = input.getOffset() + match.getMatchLength(); break; } input.moveNext(); } if (input.getOffset() > startPosition) { SymbolMatch match = textMaker.make(specification, startPosition, input.substringFrom(startPosition)); return new Step(match.getSymbol(), startPosition + match.getMatchLength()); } if (input.isEnd()) { return new Step(Symbol.emptySymbol, input.getOffset()); } return new Step(matchSymbol, newNext); }
private int wikiWordLength(String candidate) { if (candidate.length() < 3) return 0; if (!isUpperCaseLetter(candidate, 0)) return 0; if (!isDigit(candidate, 1) && !isLowerCaseLetter(candidate, 1)) return 0; int lastUpperCaseLetter = 0; int i; for (i = 2; i < candidate.length(); i++) { if (isCharacter(candidate, '_', i)) return 0; if (isUpperCaseLetter(candidate, i)) { if (i == lastUpperCaseLetter + 1) return 0; lastUpperCaseLetter = i; } else if (!isDigit(candidate, i) && !isLetter(candidate, i) /*&& !isCharacter(candidate, '.', i)*/) break; } if (lastUpperCaseLetter > 0 && i > 2) return i; return 0; }
private EditText text ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); text = (EditText)findViewById(R.id.text); text.setOnKeyListener(new TextMaker()); }
public int findWikiWordLength(String text) { String candidate = text + "."; int offset = "<>^.".contains(candidate.substring(0, 1)) ? 1 : 0; while (offset < candidate.length()) { int dot = candidate.indexOf(".", offset); int word = wikiWordLength(candidate.substring(offset, dot)); if (word == 0) return offset > 1 ? offset - 1 : 0; if (offset + word < dot) return offset + word; offset = dot + 1; } return text.length(); }
public Scanner(SourcePage sourcePage, CharSequence input) { this( new TextMaker( new VariableSource() { @Override public Maybe<String> findVariable(String name) { return Maybe.noString; } }, sourcePage), input); }
public Scanner(SourcePage sourcePage, CharSequence input) { this( new TextMaker( new VariableSource() { @Override public Maybe<String> findVariable(String name) { return Maybe.noString; } }, sourcePage), input); }
public static Parser make(ParsingPage currentPage, CharSequence input, SymbolProvider provider) { ParseSpecification specification = new ParseSpecification().provider(provider); return new Parser(null, currentPage, new Scanner(new TextMaker(currentPage, currentPage.getNamedPage()), input), specification); }
public static Parser make(ParsingPage currentPage, CharSequence input, SymbolProvider provider) { ParseSpecification specification = new ParseSpecification().provider(provider); return new Parser(null, currentPage, new Scanner(new TextMaker(currentPage, currentPage.getNamedPage()), input), specification); }
public Symbol parseWithParent(String input, Parser parent) { return new Parser(parent, currentPage, new Scanner(new TextMaker(currentPage, currentPage.getNamedPage()), input), new ParseSpecification().provider(specification)).parse(); }
public Symbol parseWithParent(String input, Parser parent) { return new Parser(parent, currentPage, new Scanner(new TextMaker(currentPage, currentPage.getNamedPage()), input), new ParseSpecification().provider(specification)).parse(); }