List of usage examples for java.util.regex Matcher start
public int start()
From source file:com.streamsets.pipeline.lib.parser.log.LEEFParser.java
@Override protected char getExtensionAttrSeparator(Matcher m, int index, StringBuilder logLine) { char attrSep = LEEF_DEFAULT_SEP; if (m.find()) { String val = logLine.substring(index, m.start()); if (val.length() == 1) { attrSep = val.charAt(0); } else {//from w w w. j a va 2s.c o m int hexStart = val.indexOf('x'); if (hexStart == -1) { attrSep = (char) Integer.parseInt(val, 16); } else { attrSep = (char) Integer.parseInt(val.substring(hexStart + 1), 16); } } } return attrSep; }
From source file:com.squarespace.template.MapFormat.java
private void init(String raw) { StringBuffer buf = new StringBuffer(); Matcher matcher = KEY_ESCAPE.matcher(raw); int mark = 0; int length = raw.length(); while (matcher.find()) { int start0 = matcher.start(); if (mark < start0) { buf.append(raw.substring(mark, start0)); }// w w w .j ava 2s . co m buf.append(raw.charAt(start0)); keys.add(raw.substring(start0 + 2, matcher.end() - 1)); mark = matcher.end(); } if (mark < length) { buf.append(raw.substring(mark, length)); } this.format = buf.toString(); }
From source file:eu.alpinweiss.filegen.util.generator.impl.SequenceGenerator.java
String[] cropPattern(String pattern) { final String[] generationPattern = new String[3]; final Pattern compile = Pattern.compile(SEQUENCE); final Matcher matcher = compile.matcher(pattern); if (matcher.find()) { generationPattern[0] = pattern.substring(0, matcher.start()); generationPattern[1] = pattern.substring(matcher.start(), matcher.end()); generationPattern[2] = pattern.substring(matcher.end(), pattern.length()); } else {//from ww w . j a v a2s . c om generationPattern[0] = ""; generationPattern[1] = pattern; generationPattern[2] = ""; } return generationPattern; }
From source file:com.mmdi.gmds.ws.pcs.resource.GeoLocationJsonResource.java
private void locateFromCache(Location location) { try {//from www . j a v a2 s .co m String pc = location.getPostalCode(); if (pc != null) { StringBuilder builder = new StringBuilder(pc); Pattern pattern = Pattern.compile("\\s"); Matcher matcher = pattern.matcher(pc); while (matcher.find()) { builder.replace(matcher.start(), matcher.end(), ""); } CacheResource cache = new PostalCodeCacheResource(); PostalCode postalCode = (PostalCode) cache.getData(builder.toString(), locateCacheRegion); if (postalCode != null) { location.setLat(postalCode.getLat()); location.setLng(postalCode.getLong()); } } } catch (CacheException ce) { logger.error(ce.getMessage()); } }
From source file:com.sangupta.dryrun.mongo.DryRunAntPath.java
/** * Returns the regular expression equivalent of this Ant path. * /*ww w. j a va2 s. c o m*/ * @return */ public String toRegex() { StringBuilder patternBuilder = new StringBuilder(); Matcher m = WILDCARD_PATTERN.matcher(path); int end = 0; while (m.find()) { patternBuilder.append(quote(path, end, m.start())); String match = m.group(); if ("?".equals(match)) { patternBuilder.append('.'); } else if ("**".equals(match)) { patternBuilder.append(".*"); } else if ("*".equals(match)) { patternBuilder.append("[^/]*"); } end = m.end(); } patternBuilder.append(quote(path, end, path.length())); return patternBuilder.toString(); }
From source file:org.springframework.core.util.AntPathStringMatcher.java
private Pattern createPattern(final String pattern) { StringBuilder patternBuilder = new StringBuilder(); Matcher m = GLOB_PATTERN.matcher(pattern); int end = 0;//from w ww .j ava 2 s .c om while (m.find()) { patternBuilder.append(quote(pattern, end, m.start())); String match = m.group(); if ("?".equals(match)) { patternBuilder.append('.'); } else if ("*".equals(match)) { patternBuilder.append(".*"); } else if (match.startsWith("{") && match.endsWith("}")) { int colonIdx = match.indexOf(':'); if (colonIdx == -1) { patternBuilder.append(DEFAULT_VARIABLE_PATTERN); variableNames.add(m.group(1)); } else { String variablePattern = match.substring(colonIdx + 1, match.length() - 1); patternBuilder.append('('); patternBuilder.append(variablePattern); patternBuilder.append(')'); String variableName = match.substring(1, colonIdx); variableNames.add(variableName); } } end = m.end(); } patternBuilder.append(quote(pattern, end, pattern.length())); return Pattern.compile(patternBuilder.toString()); }
From source file:net.java.sip.communicator.impl.gui.main.chat.replacers.URLReplacer.java
/** * Replace operation for replacing URL's with a hyperlinked version. * * @param target destination to write the replacement result to * @param piece the piece of content to be processed *///from w ww.j a va 2 s . com @Override public void replace(final StringBuilder target, final String piece) { final Matcher m = this.pattern.matcher(piece); int prevEnd = 0; while (m.find()) { target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd, m.start()))); prevEnd = m.end(); String url = m.group().trim(); target.append("<A href=\""); if (url.startsWith("www")) { target.append("http://"); } target.append(url); target.append("\">"); target.append(StringEscapeUtils.escapeHtml4(url)); target.append("</A>"); } target.append(StringEscapeUtils.escapeHtml4(piece.substring(prevEnd))); }
From source file:dk.dma.ais.transform.VdmVdoTransformer.java
@Override public AisPacket transform(AisPacket packet) { AisMessage message = packet.tryGetAisMessage(); if (message == null) { return null; }/*w ww . j ava 2 s . c o m*/ boolean own = message.getUserId() == ownMmsi; // No need to change if (message.getVdm().isOwnMessage() == own) { return packet; } // Split lines List<String> lines = packet.getStringMessageLines(); for (int i = 0; i < lines.size(); i++) { // Find where VDO/VDM starts and replace last character String line = lines.get(i); Matcher matcher = VDM_PATTERN.matcher(line); if (!matcher.find()) { continue; } int start = matcher.start(); line = line.substring(0, start + 5) + (own ? 'O' : 'M') + line.substring(start + 6); // Maybe do talker transformation if (own && ownTalker != null) { line = line.substring(0, start + 1) + ownTalker + line.substring(start + 3); } // Calculate checksum int checksum; try { checksum = Sentence.getChecksum(line.substring(start)); } catch (SentenceException e) { e.printStackTrace(); return null; } String strChecksum = Sentence.getStringChecksum(checksum); // Find where checksum starts and replace checksum start = line.indexOf('*', start); line = line.substring(0, start + 1) + strChecksum + line.substring(start + 3); lines.set(i, line); } return AisPacket.from(StringUtils.join(lines, "\r\n")); }
From source file:io.kahu.hawaii.util.call.http.util.UriBuilder.java
private void substitutePathVariables(StringBuilder builder, String url) { Matcher matcher = pathVariablePattern.matcher(url); int currentPos = 0; int matchNumber = 0; while (matcher.find()) { int matchStart = matcher.start(); if (matchStart > currentPos) { builder.append(url.substring(currentPos, matchStart)); }// ww w.j a va 2 s . c o m builder.append(pathVariables[matchNumber]); currentPos = matcher.end(); matchNumber++; } if (currentPos < url.length()) { builder.append(url.substring(currentPos)); } if (matchNumber != pathVariables.length) { System.err.println("Substitution for '" + url + "' got '" + pathVariables.length + "' variables and the number of groups is '" + matcher.groupCount() + "'."); } }
From source file:com.squarespace.less.core.MapFormat.java
/** * Extracts the keys from the pattern and generates the format string. *///w w w .j av a2 s . c om private String init(String raw) { StringBuffer buf = new StringBuffer(); Matcher matcher = KEY_ESCAPE.matcher(raw); int mark = 0; int length = raw.length(); while (matcher.find()) { int start0 = matcher.start(); if (mark < start0) { buf.append(raw.substring(mark, start0)); } buf.append(raw.charAt(start0)); keys.add(raw.substring(start0 + 2, matcher.end() - 1)); mark = matcher.end(); } if (mark < length) { buf.append(raw.substring(mark, length)); } return buf.toString(); }