List of usage examples for org.apache.commons.lang StringUtils stripStart
public static String stripStart(String str, String stripChars)
Strips any of a set of characters from the start of a String.
From source file:com.livinglogic.ul4.BoundStringMethodLStrip.java
public static String call(String object) { return StringUtils.stripStart(object, null); }
From source file:com.livinglogic.ul4.BoundStringMethodLStrip.java
public static String call(String object, String chars) { return StringUtils.stripStart(object, chars); }
From source file:de.iew.stagediver.fx.database.liquibase.impl.ClasspathResourceAccessorImpl.java
/** * {@inheritDoc}/*from w w w . ja va 2 s.c o m*/ * <p> * This method is overloaded to strip of an {@code /}-characters from the beginning of {@code file}. * </p> * * @param file the path to the resource * @return an input stream to the resource * @throws IOException if an io error occured */ @Override public InputStream getResourceAsStream(final String file) throws IOException { if (file == null) { return null; } final String strippedFilename = StringUtils.stripStart(file, "/"); return super.getResourceAsStream(strippedFilename); }
From source file:com.intellij.react.css.modules.psi.CssModulesIndexedStylesVarPsiReferenceContributor.java
@Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider(CssModulesUtil.STRING_PATTERN, new PsiReferenceProvider() { @NotNull/*from w w w.j a v a2 s . c o m*/ @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { final PsiElement cssClassNamesImportOrRequire = CssModulesUtil .getCssClassNamesImportOrRequireDeclaration((JSLiteralExpression) element); if (cssClassNamesImportOrRequire != null) { final String literalClass = "." + StringUtils.stripStart(StringUtils.stripEnd(element.getText(), "\"'"), "\"'"); final Ref<StylesheetFile> referencedStyleSheet = new Ref<>(); final CssClass cssClass = CssModulesUtil.getCssClass(cssClassNamesImportOrRequire, literalClass, referencedStyleSheet); if (cssClass != null) { return new PsiReference[] { new PsiReferenceBase<PsiElement>(element) { @Nullable @Override public PsiElement resolve() { return cssClass; } @NotNull @Override public Object[] getVariants() { return new Object[0]; } } }; } else { if (referencedStyleSheet.get() != null) { final TextRange rangeInElement = TextRange.from(1, element.getTextLength() - 2); // minus string quotes return new PsiReference[] { new CssModulesUnknownClassPsiReference(element, rangeInElement, referencedStyleSheet.get()) }; } } } return new PsiReference[0]; } }); }
From source file:edu.usu.sdl.openstorefront.usecase.SantizeUseCase.java
@Test public void testStringPadRemoval() { System.out.println(StringUtils.stripStart("0001", "0")); System.out.println(StringUtils.stripStart("0301", "0")); System.out.println(StringUtils.stripStart("5", "0")); System.out.println(StringUtils.stripStart("0000", "0")); System.out.println(StringUtils.stripStart("1000", "0")); System.out.println(StringUtils.stripStart("0020", "0")); System.out.println(StringUtils.stripStart("bob", "0")); }
From source file:com.dinochiesa.edgecallouts.util.CalloutUtil.java
/** * Strips all leading and trailing characters from the given string. * Does NOT strip characters in the middle, and strips the leading and * trailing characters respectively./*w w w. j a v a 2 s .c om*/ * e.g. "{abc}", "{", "}" returns "abc" * e.g. "aabccxyz", "ba", "z" returns "ccxy" * * @param toStrip The String to remove characters from * @param start The characters to remove from the start (in any order) * @param end The characters to remove from the end (in any order) * @return String with leading and trailing characters stripped */ public static String stripStartAndEnd(String toStrip, String start, String end) { if (StringUtils.isBlank(toStrip)) { throw new IllegalArgumentException("toStrip must not be blank or null"); } return StringUtils.stripEnd(StringUtils.stripStart(toStrip, start), end); }
From source file:com.adobe.acs.tools.tag_maker.tagdataconverters.impl.LowercaseWithDashesConverterImpl.java
@Override public final TagData convert(final String data) { String title = data;//from w w w . ja v a 2 s . co m String name = data; name = StringUtils.stripToEmpty(name); name = StringUtils.lowerCase(name); name = StringUtils.replace(name, "&", " and "); name = StringUtils.replace(name, "/", " or "); name = StringUtils.replace(name, "%", " percent "); name = name.replaceAll("[^a-z0-9-]+", "-"); name = StringUtils.stripEnd(name, "-"); name = StringUtils.stripStart(name, "-"); final TagData tagData = new TagData(name); tagData.setTitle(title); return tagData; }
From source file:com.seer.datacruncher.datastreams.CreateXMLFromFlatFileFixedPosition.java
public DatastreamDTO createXMLFromFlatFileFixedPosition(DatastreamDTO dataStreamDTO) { String datastream = dataStreamDTO.getInput(); String fieldValue;//w w w. j a va 2 s . c o m String fillChar; int beginIndex = 0; int endIndex = 0; int lenght = datastream.length(); List<SchemaFieldEntity> listSchemaFields = schemaFieldsDao.listSchemaFields(dataStreamDTO.getIdSchema()); List<String> listValues = new ArrayList<String>(); for (int cont = 0; cont < listSchemaFields.size(); cont++) { endIndex = beginIndex + Integer.parseInt(listSchemaFields.get(cont).getSize()); if (endIndex > lenght) { dataStreamDTO.setSuccess(false); dataStreamDTO.setMessage(I18n.getMessage("error.lenghtNotValid")); return dataStreamDTO; } fieldValue = datastream.substring(beginIndex, endIndex); beginIndex = endIndex; if (listSchemaFields.get(cont).getIdFieldType() != FieldType.date) { fillChar = listSchemaFields.get(cont).getFillChar(); if (listSchemaFields.get(cont).getIdAlign() == null || listSchemaFields.get(cont).getIdAlign() == 1) { fieldValue = StringUtils.stripEnd(fieldValue, fillChar); } else { fieldValue = StringUtils.stripStart(fieldValue, fillChar); } } fieldValue = fieldValue.replaceAll("&", "&"); listValues.add(fieldValue); } if (endIndex != lenght) { dataStreamDTO.setSuccess(false); dataStreamDTO.setMessage(I18n.getMessage("error.lenghtNotValid")); } else { StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); stringBuffer.append("<" + Tag.TAG_ROOT + ">\n"); for (int cont = 0; cont < listSchemaFields.size(); cont++) { if (!listSchemaFields.get(cont).getNillable() || listValues.get(cont).length() > 0) { stringBuffer.append("\t<" + listSchemaFields.get(cont).getName() + ">" + listValues.get(cont) + "</" + listSchemaFields.get(cont).getName() + ">\n"); } } stringBuffer.append("</" + Tag.TAG_ROOT + ">\n"); dataStreamDTO.setSuccess(true); dataStreamDTO.setOutput(stringBuffer.toString()); } log.info(dataStreamDTO.getOutput()); return dataStreamDTO; }
From source file:edu.ku.brc.specify.ui.CatalogNumberFormatter.java
public String format(final Object dataValue) { if (dataValue != null && dataValue instanceof String) { return StringUtils.stripStart((String) dataValue, "0"); }/* w w w .j av a 2s. c om*/ return ""; }
From source file:edu.ku.brc.af.ui.ESTermParser.java
@Override public boolean parse(final String searchTermArg, final boolean parseAsSingleTerm) { instance.fields.clear();/*from www . j a v a 2 s . co m*/ //DateWrapper scrDateFormat = AppPrefsCache.getDateWrapper("ui", "formatting", "scrdateformat"); int currentYear = Calendar.getInstance().get(Calendar.YEAR); String searchTerm = searchTermArg; DateParser dd = new DateParser(instance.scrDateFormat.getSimpleDateFormat().toPattern()); //---------------------------------------------------------------------------------------------- // NOTE: If a full date was type in and it was parsed as such // and it couldn't be something else, then it only searches date fields. //---------------------------------------------------------------------------------------------- int cnt = 0; if (searchTerm.length() > 0) { if (StringUtils.contains(searchTerm, '\\')) { return false; } String[] terms; boolean startWith = searchTerm.startsWith("*"); boolean endsWith = searchTerm.endsWith("*"); searchTerm = StringUtils.remove(searchTerm, '*'); if (searchTerm.startsWith("\"") || searchTerm.startsWith("'") || searchTerm.startsWith("`")) { searchTerm = StringUtils.stripStart(searchTerm, "\"'`"); searchTerm = StringUtils.stripEnd(searchTerm, "\"'`"); terms = new String[] { searchTerm }; } else if (parseAsSingleTerm) { terms = new String[] { searchTerm }; } else { terms = StringUtils.split(searchTerm, ' '); } if (terms.length == 1) { terms[0] = (startWith ? "*" : "") + terms[0] + (endsWith ? "*" : ""); } else { terms[0] = (startWith ? "*" : "") + terms[0]; terms[terms.length - 1] = terms[terms.length - 1] + (endsWith ? "*" : ""); } for (String term : terms) { if (StringUtils.isEmpty(term)) { continue; } SearchTermField stf = new SearchTermField(term); if (stf.isSingleChar()) { return false; } instance.fields.add(stf); cnt += !stf.isSingleChar() ? 1 : 0; //log.debug(term); String termStr = term; if (termStr.startsWith("*")) { stf.setOption(SearchTermField.STARTS_WILDCARD); termStr = termStr.substring(1); stf.setTerm(termStr); } if (termStr.endsWith("*")) { stf.setOption(SearchTermField.ENDS_WILDCARD); termStr = termStr.substring(0, termStr.length() - 1); stf.setTerm(termStr); } // First check to see if it is all numeric. if (StringUtils.isNumeric(termStr)) { stf.setOption(SearchTermField.IS_NUMERIC); if (StringUtils.contains(termStr, '.')) { stf.setOption(SearchTermField.HAS_DEC_POINT); } if (!stf.isOn(SearchTermField.HAS_DEC_POINT) && termStr.length() == 4) { int year = Integer.parseInt(termStr); if (year > 1000 && year <= currentYear) { stf.setOption(SearchTermField.IS_YEAR_OF_DATE); } } } else { // Check to see if it is date Date searchDate = dd.parseDate(searchTermArg); if (searchDate != null) { try { termStr = dbDateFormat.format(searchDate); stf.setTerm(termStr); stf.setOption(SearchTermField.IS_DATE); } catch (Exception ex) { edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ESTermParser.class, ex); // should never get here } } } } } return instance.fields.size() > 0 && cnt > 0; }