List of usage examples for java.lang CharSequence subSequence
CharSequence subSequence(int start, int end);
From source file:fr.smile.liferay.LiferayUrlRewriter.java
/** * Fix all resources urls and return the result. * * @param input The original charSequence to be processed. * @param requestUrl The request URL.// w w w. jav a 2 s . c om * @param baseUrlParam The base URL selected for this request. * @return the result of this renderer. */ public CharSequence rewriteHtml(CharSequence input, String requestUrl, Pattern pattern, String baseUrlParam, String visibleBaseUrl) { if (LOG.isDebugEnabled()) { LOG.debug("input=" + input); LOG.debug("rewriteHtml (requestUrl=" + requestUrl + ", pattern=" + pattern + ",baseUrlParam)" + baseUrlParam + ",strVisibleBaseUrl=" + visibleBaseUrl + ")"); } StringBuffer result = new StringBuffer(input.length()); Matcher m = pattern.matcher(input); while (m.find()) { if (LOG.isTraceEnabled()) { LOG.trace("found match: " + m); } String url = input.subSequence(m.start(3) + 1, m.end(3) - 1).toString(); url = rewriteUrl(url, requestUrl, baseUrlParam, visibleBaseUrl); url = url.replaceAll("\\$", "\\\\\\$"); // replace '$' -> '\$' as it // denotes group StringBuffer tagReplacement = new StringBuffer("<$1$2=\"").append(url).append("\""); if (m.groupCount() > 3) { tagReplacement.append("$4"); } tagReplacement.append('>'); if (LOG.isTraceEnabled()) { LOG.trace("replacement: " + tagReplacement); } m.appendReplacement(result, tagReplacement.toString()); } m.appendTail(result); return result; }
From source file:com.cyberway.issue.crawler.extractor.ExtractorHTML.java
/** * Handle generic HREF cases./* ww w. j av a 2 s .c om*/ * * @param curi * @param value * @param context */ protected void processLink(CrawlURI curi, final CharSequence value, CharSequence context) { if (TextUtils.matches(JAVASCRIPT, value) || TextUtils.matches(JAVASCRIPT2, value)) { processScriptCode(curi, value.subSequence(11, value.length())); } else { if (logger.isLoggable(Level.FINEST)) { logger.finest("link: " + value.toString() + " from " + curi); } addLinkFromString(curi, (value instanceof String) ? (String) value : value.toString(), context, Link.NAVLINK_HOP); this.numberOfLinksExtracted++; } }
From source file:org.juzu.impl.template.ASTBuilder.java
private ASTNode.Template build(CharSequence s, CharSequenceReader reader) { ////from ww w . java2s .c om TemplateParser parser = new TemplateParser(new OffsetTokenManager(new OffsetCharStream(reader))); // try { parser.parse(); } catch (ParseException e) { throw new AssertionError(e); } // List<ASTNode.Block> blocks = new ArrayList<ASTNode.Block>(); int previousOffset = 0; Location previousPosition = new Location(1, 1); for (int i = 0; i < parser.list.size(); i++) { ASTNode.Block block = parser.list.get(i); // if (block.getBeginOffset() > previousOffset) { blocks.add(new ASTNode.Section(SectionType.STRING, previousOffset, block.getBeginOffset(), s.subSequence(previousOffset, block.getBeginOffset()).toString(), previousPosition, block.getEndPosition())); } blocks.add(block); previousOffset = block.getEndOffset(); previousPosition = block.getEndPosition(); } // if (previousOffset < s.length()) { blocks.add(new ASTNode.Section(SectionType.STRING, previousOffset, s.length(), s.subSequence(previousOffset, s.length()).toString(), previousPosition, new Location(parser.token.endColumn, parser.token.endLine))); } // return new ASTNode.Template(Collections.unmodifiableList(blocks)); }
From source file:netbeanstypescript.TSStructureScanner.java
@Override public Map<String, List<OffsetRange>> folds(ParserResult pr) { Object arr = TSService.call("getFolds", pr.getSnapshot().getSource().getFileObject()); if (arr == null) { return Collections.emptyMap(); }// ww w. ja v a2 s . c o m List<OffsetRange> ranges = new ArrayList<>(); CharSequence text = pr.getSnapshot().getText(); for (JSONObject span : (List<JSONObject>) arr) { int start = ((Number) span.get("start")).intValue(); int end = ((Number) span.get("end")).intValue(); if (text.charAt(start) == '/') { // ts.OutliningElementsCollector creates folds for sequences of multiple //-comments // preceding a declaration, but this can prevent NetBeans's <editor-fold> directives // from working. Remove all lines up to and including the last such directive. int startDelta = 0; for (Matcher m = editorFolds.matcher(text.subSequence(start, end)); m.find();) { startDelta = m.end(); } start += startDelta; // There may be only a single line left - for consistency, don't fold it if (text.subSequence(start, end).toString().indexOf('\n') < 0) { continue; } } ranges.add(new OffsetRange(start, end)); } return Collections.singletonMap("codeblocks", ranges); }
From source file:org.chromium.chrome.browser.payments.ui.EditorView.java
/** * Builds the editor view./*from ww w . j av a2s .c om*/ * * @param activity The activity on top of which the UI should be displayed. * @param observerForTest Optional event observer for testing. */ public EditorView(Activity activity, PaymentRequestObserverForTest observerForTest) { super(activity, R.style.FullscreenWhite); // Sets transparent background for animating content view. getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); mContext = activity; mObserverForTest = observerForTest; mHandler = new Handler(); mEditorActionListener = new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { mDoneButton.performClick(); return true; } else if (actionId == EditorInfo.IME_ACTION_NEXT) { View next = v.focusSearch(View.FOCUS_FORWARD); if (next != null) { next.requestFocus(); return true; } } return false; } }; mHalfRowMargin = activity.getResources().getDimensionPixelSize(R.dimen.payments_section_large_spacing); mFieldViews = new ArrayList<>(); mEditableTextFields = new ArrayList<>(); mDropdownFields = new ArrayList<>(); final Pattern cardNumberPattern = Pattern.compile("^[\\d- ]*$"); mCardNumberInputFilter = new InputFilter() { @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { // Accept deletions. if (start == end) return null; // Accept digits, "-", and spaces. if (cardNumberPattern.matcher(source.subSequence(start, end)).matches()) { return null; } // Reject everything else. return ""; } }; mCardNumberFormatter = new CreditCardNumberFormattingTextWatcher(); new AsyncTask<Void, Void, PhoneNumberFormattingTextWatcher>() { @Override protected PhoneNumberFormattingTextWatcher doInBackground(Void... unused) { return new PhoneNumberFormattingTextWatcher(); } @Override protected void onPostExecute(PhoneNumberFormattingTextWatcher result) { mPhoneFormatter = result; if (mPhoneInput != null) { mPhoneInput.addTextChangedListener(mPhoneFormatter); } } }.execute(); }
From source file:wicket.protocol.http.request.CryptedUrlWebRequestCodingStrategy.java
/** * Returns the given url encoded.// ww w. j av a 2 s .c o m * * @param url * The URL to encode * @return The encoded url */ protected CharSequence encodeURL(final CharSequence url) { // Get the crypt implementation from the application ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt(); if (urlCrypt != null) { // The url must have a query string, otherwise keep the url // unchanged final int pos = url.toString().indexOf('?'); if (pos > 0) { // The url's path CharSequence urlPrefix = url.subSequence(0, pos); // Extract the querystring String queryString = url.subSequence(pos + 1, url.length()).toString(); // if the querystring starts with a parameter like // "x=", than don't change the querystring as it // has been encoded already if (!queryString.startsWith("x=")) { // The length of the encrypted string depends on the // length of the original querystring. Let's try to // make the querystring shorter first without loosing // information. queryString = shortenUrl(queryString).toString(); // encrypt the query string String encryptedQueryString = urlCrypt.encryptUrlSafe(queryString); try { encryptedQueryString = URLEncoder.encode(encryptedQueryString, Application.get().getRequestCycleSettings().getResponseRequestEncoding()); } catch (UnsupportedEncodingException ex) { throw new WicketRuntimeException(ex); } // build the new complete url return new AppendingStringBuffer(urlPrefix).append("?x=").append(encryptedQueryString); } } } // we didn't change anything return url; }
From source file:com.dwdesign.tweetings.adapter.UserAutoCompleteAdapter.java
@Override public Cursor runQueryOnBackgroundThread(CharSequence constraint) { if (mCursorClosed) return null; final FilterQueryProvider filter = getFilterQueryProvider(); if (filter != null) return filter.runQuery(constraint); final StringBuilder where = new StringBuilder(); constraint = constraint != null ? constraint.toString().replaceAll("_", "^_") : null; constraint = constraint != null ? constraint.toString().replaceAll("'", "") : null; isHash = false;/*from www .j a v a 2 s . c o m*/ if (constraint != null) { if (constraint.length() > 1 && constraint.charAt(0) == '@') { isHash = false; mLookupText = null; final String lookup = constraint.subSequence(1, constraint.length() - 1).toString(); where.append(CachedUsers.SCREEN_NAME + " LIKE '" + lookup + "%' ESCAPE '^'"); where.append(" OR "); where.append(CachedUsers.NAME + " LIKE '" + lookup + "%' ESCAPE '^'"); return mResolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, lookup != null ? where.toString() : null, null, null); } else if (constraint.length() > 0 && constraint.charAt(0) == '@') { isHash = false; mLookupText = null; return mResolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, null, null, null); } else if (constraint.length() > 1 && constraint.charAt(0) == '#') { isHash = true; mLookupText = constraint.toString(); where.append(Statuses.TEXT_PLAIN + " LIKE '%" + constraint + "%' ESCAPE '^'"); return mResolver.query(Statuses.CONTENT_URI, Statuses.COLUMNS, constraint != null ? where.toString() : null, null, null); } else if (constraint.length() > 0 && constraint.charAt(0) == '#') { isHash = true; mLookupText = null; return mResolver.query(Statuses.CONTENT_URI, Statuses.COLUMNS, null, null, null); } } return null; }
From source file:br.msf.commons.util.CharSequenceUtils.java
public static List<String> split(final CharSequence sequence, final Pattern pattern, final boolean ignoreBlank) { if (isBlankOrNull(sequence)) { return CollectionUtils.EMPTY_LIST; }// w w w . j ava 2 s . c o m if (pattern == null) { return Collections.singletonList(sequence.toString()); } final Collection<MatchEntry> occurrences = findPattern(pattern, sequence); final List<String> split = new ArrayList<String>(occurrences.size() + 1); int start = 0; for (MatchEntry occurrence : occurrences) { final CharSequence sub = sequence.subSequence(start, occurrence.getStart()); start = occurrence.getEnd(); if (CharSequenceUtils.isBlankOrNull(sub) && ignoreBlank) { continue; } split.add(sub.toString()); } final CharSequence sub = sequence.subSequence(start, sequence.length()); if (CharSequenceUtils.isNotBlank(sub) || !ignoreBlank) { split.add(sub.toString()); } return split; }
From source file:com.github.irshulx.Components.InputExtensions.java
public CharSequence noLeadingwhiteLines(CharSequence text) { if (text.length() == 0) return text; while (text.charAt(0) == '\n') { text = text.subSequence(1, text.length()); }//from w w w . ja v a 2 s . c o m return text; }
From source file:com.github.irshulx.Components.InputExtensions.java
public CharSequence noTrailingwhiteLines(CharSequence text) { if (text.length() == 0) return text; while (text.charAt(text.length() - 1) == '\n') { text = text.subSequence(0, text.length() - 1); }/* w w w. ja va2 s . co m*/ return text; }