Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 57BD2200C5B for ; Sun, 12 Mar 2017 03:08:15 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 565D0160B88; Sun, 12 Mar 2017 02:08:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 85081160BAD for ; Sun, 12 Mar 2017 03:08:10 +0100 (CET) Received: (qmail 53355 invoked by uid 500); 12 Mar 2017 02:08:09 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 53027 invoked by uid 99); 12 Mar 2017 02:08:09 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 12 Mar 2017 02:08:09 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id B07603A208A for ; Sun, 12 Mar 2017 02:08:07 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1008161 [39/44] - in /websites/production/commons/content/proper/commons-text: ./ apidocs/ apidocs/org/apache/commons/text/ apidocs/org/apache/commons/text/class-use/ apidocs/org/apache/commons/text/diff/ apidocs/org/apache/commons/text/di... Date: Sun, 12 Mar 2017 02:08:05 -0000 To: notifications@commons.apache.org From: chtompki@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170312020807.B07603A208A@svn01-us-west.apache.org> archived-at: Sun, 12 Mar 2017 02:08:15 -0000 Modified: websites/production/commons/content/proper/commons-text/xref/org/apache/commons/text/StrSubstitutor.html ============================================================================== --- websites/production/commons/content/proper/commons-text/xref/org/apache/commons/text/StrSubstitutor.html (original) +++ websites/production/commons/content/proper/commons-text/xref/org/apache/commons/text/StrSubstitutor.html Sun Mar 12 02:08:01 2017 @@ -160,7 +160,7 @@ 152 */ 153 private StrMatcher suffixMatcher; 154 /** -155 * Stores the default variable value delimiter +155 * Stores the default variable value delimiter. 156 */ 157 private StrMatcher valueDelimiterMatcher; 158 /** @@ -203,1022 +203,1035 @@ 195 * @return the result of the replace operation 196 * @throws IllegalArgumentException if the prefix or suffix is null 197 */ -198 public static <V> String replace(final Object source, final Map<String, V> valueMap, final String prefix, final String suffix) { -199 return new StrSubstitutor(valueMap, prefix, suffix).replace(source); -200 } -201 -202 /** -203 * Replaces all the occurrences of variables in the given source object with their matching -204 * values from the properties. -205 * -206 * @param source the source text containing the variables to substitute, null returns null -207 * @param valueProperties the properties with values, may be null -208 * @return the result of the replace operation -209 */ -210 public static String replace(final Object source, final Properties valueProperties) { -211 if (valueProperties == null) { -212 return source.toString(); -213 } -214 final Map<String,String> valueMap = new HashMap<>(); -215 final Enumeration<?> propNames = valueProperties.propertyNames(); -216 while (propNames.hasMoreElements()) { -217 final String propName = (String)propNames.nextElement(); -218 final String propValue = valueProperties.getProperty(propName); -219 valueMap.put(propName, propValue); -220 } -221 return StrSubstitutor.replace(source, valueMap); -222 } -223 -224 /** -225 * Replaces all the occurrences of variables in the given source object with -226 * their matching values from the system properties. -227 * -228 * @param source the source text containing the variables to substitute, null returns null -229 * @return the result of the replace operation -230 */ -231 public static String replaceSystemProperties(final Object source) { -232 return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); -233 } -234 -235 //----------------------------------------------------------------------- -236 /** -237 * Creates a new instance with defaults for variable prefix and suffix -238 * and the escaping character. -239 */ -240 public StrSubstitutor() { -241 this((StrLookup<?>) null, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); -242 } -243 -244 /** -245 * Creates a new instance and initializes it. Uses defaults for variable -246 * prefix and suffix and the escaping character. -247 * -248 * @param <V> the type of the values in the map -249 * @param valueMap the map with the variables' values, may be null -250 */ -251 public <V> StrSubstitutor(final Map<String, V> valueMap) { -252 this(StrLookup.mapLookup(valueMap), DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); -253 } -254 -255 /** -256 * Creates a new instance and initializes it. Uses a default escaping character. -257 * -258 * @param <V> the type of the values in the map -259 * @param valueMap the map with the variables' values, may be null -260 * @param prefix the prefix for variables, not null -261 * @param suffix the suffix for variables, not null -262 * @throws IllegalArgumentException if the prefix or suffix is null -263 */ -264 public <V> StrSubstitutor(final Map<String, V> valueMap, final String prefix, final String suffix) { -265 this(StrLookup.mapLookup(valueMap), prefix, suffix, DEFAULT_ESCAPE); -266 } -267 -268 /** -269 * Creates a new instance and initializes it. -270 * -271 * @param <V> the type of the values in the map -272 * @param valueMap the map with the variables' values, may be null -273 * @param prefix the prefix for variables, not null -274 * @param suffix the suffix for variables, not null -275 * @param escape the escape character -276 * @throws IllegalArgumentException if the prefix or suffix is null -277 */ -278 public <V> StrSubstitutor(final Map<String, V> valueMap, final String prefix, final String suffix, -279 final char escape) { -280 this(StrLookup.mapLookup(valueMap), prefix, suffix, escape); -281 } -282 -283 /** -284 * Creates a new instance and initializes it. -285 * -286 * @param <V> the type of the values in the map -287 * @param valueMap the map with the variables' values, may be null -288 * @param prefix the prefix for variables, not null -289 * @param suffix the suffix for variables, not null -290 * @param escape the escape character -291 * @param valueDelimiter the variable default value delimiter, may be null -292 * @throws IllegalArgumentException if the prefix or suffix is null -293 */ -294 public <V> StrSubstitutor(final Map<String, V> valueMap, final String prefix, final String suffix, -295 final char escape, final String valueDelimiter) { -296 this(StrLookup.mapLookup(valueMap), prefix, suffix, escape, valueDelimiter); -297 } -298 -299 /** -300 * Creates a new instance and initializes it. -301 * -302 * @param variableResolver the variable resolver, may be null -303 */ -304 public StrSubstitutor(final StrLookup<?> variableResolver) { -305 this(variableResolver, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); -306 } -307 -308 /** -309 * Creates a new instance and initializes it. -310 * -311 * @param variableResolver the variable resolver, may be null -312 * @param prefix the prefix for variables, not null -313 * @param suffix the suffix for variables, not null -314 * @param escape the escape character -315 * @throws IllegalArgumentException if the prefix or suffix is null -316 */ -317 public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, -318 final char escape) { -319 this.setVariableResolver(variableResolver); -320 this.setVariablePrefix(prefix); -321 this.setVariableSuffix(suffix); -322 this.setEscapeChar(escape); -323 this.setValueDelimiterMatcher(DEFAULT_VALUE_DELIMITER); -324 } -325 -326 /** -327 * Creates a new instance and initializes it. -328 * -329 * @param variableResolver the variable resolver, may be null -330 * @param prefix the prefix for variables, not null -331 * @param suffix the suffix for variables, not null -332 * @param escape the escape character -333 * @param valueDelimiter the variable default value delimiter string, may be null -334 * @throws IllegalArgumentException if the prefix or suffix is null -335 */ -336 public StrSubstitutor(final StrLookup<?> variableResolver, final String prefix, final String suffix, -337 final char escape, final String valueDelimiter) { -338 this.setVariableResolver(variableResolver); -339 this.setVariablePrefix(prefix); -340 this.setVariableSuffix(suffix); -341 this.setEscapeChar(escape); -342 this.setValueDelimiter(valueDelimiter); -343 } -344 -345 /** -346 * Creates a new instance and initializes it. -347 * -348 * @param variableResolver the variable resolver, may be null -349 * @param prefixMatcher the prefix for variables, not null -350 * @param suffixMatcher the suffix for variables, not null -351 * @param escape the escape character -352 * @throws IllegalArgumentException if the prefix or suffix is null -353 */ -354 public StrSubstitutor( -355 final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, -356 final char escape) { -357 this(variableResolver, prefixMatcher, suffixMatcher, escape, DEFAULT_VALUE_DELIMITER); -358 } -359 -360 /** -361 * Creates a new instance and initializes it. -362 * -363 * @param variableResolver the variable resolver, may be null -364 * @param prefixMatcher the prefix for variables, not null -365 * @param suffixMatcher the suffix for variables, not null -366 * @param escape the escape character -367 * @param valueDelimiterMatcher the variable default value delimiter matcher, may be null -368 * @throws IllegalArgumentException if the prefix or suffix is null -369 */ -370 public StrSubstitutor( -371 final StrLookup<?> variableResolver, final StrMatcher prefixMatcher, final StrMatcher suffixMatcher, -372 final char escape, final StrMatcher valueDelimiterMatcher) { -373 this.setVariableResolver(variableResolver); -374 this.setVariablePrefixMatcher(prefixMatcher); -375 this.setVariableSuffixMatcher(suffixMatcher); -376 this.setEscapeChar(escape); -377 this.setValueDelimiterMatcher(valueDelimiterMatcher); -378 } -379 -380 //----------------------------------------------------------------------- -381 /** -382 * Replaces all the occurrences of variables with their matching values -383 * from the resolver using the given source string as a template. -384 * -385 * @param source the string to replace in, null returns null -386 * @return the result of the replace operation -387 */ -388 public String replace(final String source) { -389 if (source == null) { -390 return null; -391 } -392 final StrBuilder buf = new StrBuilder(source); -393 if (substitute(buf, 0, source.length()) == false) { -394 return source; -395 } -396 return buf.toString(); -397 } -398 -399 /** -400 * Replaces all the occurrences of variables with their matching values -401 * from the resolver using the given source string as a template. -402 * <p> -403 * Only the specified portion of the string will be processed. -404 * The rest of the string is not processed, and is not returned. -405 * -406 * @param source the string to replace in, null returns null -407 * @param offset the start offset within the array, must be valid -408 * @param length the length within the array to be processed, must be valid -409 * @return the result of the replace operation -410 */ -411 public String replace(final String source, final int offset, final int length) { -412 if (source == null) { -413 return null; -414 } -415 final StrBuilder buf = new StrBuilder(length).append(source, offset, length); -416 if (substitute(buf, 0, length) == false) { -417 return source.substring(offset, offset + length); -418 } -419 return buf.toString(); -420 } -421 -422 //----------------------------------------------------------------------- -423 /** -424 * Replaces all the occurrences of variables with their matching values -425 * from the resolver using the given source array as a template. -426 * The array is not altered by this method. -427 * -428 * @param source the character array to replace in, not altered, null returns null -429 * @return the result of the replace operation -430 */ -431 public String replace(final char[] source) { -432 if (source == null) { -433 return null; -434 } -435 final StrBuilder buf = new StrBuilder(source.length).append(source); -436 substitute(buf, 0, source.length); -437 return buf.toString(); -438 } -439 -440 /** -441 * Replaces all the occurrences of variables with their matching values -442 * from the resolver using the given source array as a template. -443 * The array is not altered by this method. -444 * <p> -445 * Only the specified portion of the array will be processed. -446 * The rest of the array is not processed, and is not returned. -447 * -448 * @param source the character array to replace in, not altered, null returns null -449 * @param offset the start offset within the array, must be valid -450 * @param length the length within the array to be processed, must be valid -451 * @return the result of the replace operation -452 */ -453 public String replace(final char[] source, final int offset, final int length) { -454 if (source == null) { -455 return null; -456 } -457 final StrBuilder buf = new StrBuilder(length).append(source, offset, length); -458 substitute(buf, 0, length); -459 return buf.toString(); -460 } -461 -462 //----------------------------------------------------------------------- -463 /** -464 * Replaces all the occurrences of variables with their matching values -465 * from the resolver using the given source buffer as a template. -466 * The buffer is not altered by this method. -467 * -468 * @param source the buffer to use as a template, not changed, null returns null -469 * @return the result of the replace operation -470 */ -471 public String replace(final StringBuffer source) { -472 if (source == null) { -473 return null; -474 } -475 final StrBuilder buf = new StrBuilder(source.length()).append(source); -476 substitute(buf, 0, buf.length()); -477 return buf.toString(); -478 } -479 -480 /** -481 * Replaces all the occurrences of variables with their matching values -482 * from the resolver using the given source buffer as a template. -483 * The buffer is not altered by this method. -484 * <p> -485 * Only the specified portion of the buffer will be processed. -486 * The rest of the buffer is not processed, and is not returned. -487 * -488 * @param source the buffer to use as a template, not changed, null returns null -489 * @param offset the start offset within the array, must be valid -490 * @param length the length within the array to be processed, must be valid -491 * @return the result of the replace operation -492 */ -493 public String replace(final StringBuffer source, final int offset, final int length) { -494 if (source == null) { -495 return null; -496 } -497 final StrBuilder buf = new StrBuilder(length).append(source, offset, length); -498 substitute(buf, 0, length); -499 return buf.toString(); -500 } -501 -502 /** -503 * Replaces all the occurrences of variables with their matching values -504 * from the resolver using the given source as a template. -505 * The source is not altered by this method. -506 * -507 * @param source the buffer to use as a template, not changed, null returns null -508 * @return the result of the replace operation -509 */ -510 public String replace(final CharSequence source) { -511 if (source == null) { -512 return null; -513 } -514 return replace(source, 0, source.length()); -515 } -516 -517 /** -518 * Replaces all the occurrences of variables with their matching values -519 * from the resolver using the given source as a template. -520 * The source is not altered by this method. -521 * <p> -522 * Only the specified portion of the buffer will be processed. -523 * The rest of the buffer is not processed, and is not returned. -524 * -525 * @param source the buffer to use as a template, not changed, null returns null -526 * @param offset the start offset within the array, must be valid -527 * @param length the length within the array to be processed, must be valid -528 * @return the result of the replace operation -529 */ -530 public String replace(final CharSequence source, final int offset, final int length) { -531 if (source == null) { -532 return null; -533 } -534 final StrBuilder buf = new StrBuilder(length).append(source, offset, length); -535 substitute(buf, 0, length); -536 return buf.toString(); -537 } -538 -539 //----------------------------------------------------------------------- -540 /** -541 * Replaces all the occurrences of variables with their matching values -542 * from the resolver using the given source builder as a template. -543 * The builder is not altered by this method. -544 * -545 * @param source the builder to use as a template, not changed, null returns null -546 * @return the result of the replace operation -547 */ -548 public String replace(final StrBuilder source) { -549 if (source == null) { -550 return null; -551 } -552 final StrBuilder buf = new StrBuilder(source.length()).append(source); -553 substitute(buf, 0, buf.length()); -554 return buf.toString(); -555 } -556 -557 /** -558 * Replaces all the occurrences of variables with their matching values -559 * from the resolver using the given source builder as a template. -560 * The builder is not altered by this method. -561 * <p> -562 * Only the specified portion of the builder will be processed. -563 * The rest of the builder is not processed, and is not returned. -564 * -565 * @param source the builder to use as a template, not changed, null returns null -566 * @param offset the start offset within the array, must be valid -567 * @param length the length within the array to be processed, must be valid -568 * @return the result of the replace operation -569 */ -570 public String replace(final StrBuilder source, final int offset, final int length) { -571 if (source == null) { -572 return null; -573 } -574 final StrBuilder buf = new StrBuilder(length).append(source, offset, length); -575 substitute(buf, 0, length); -576 return buf.toString(); -577 } -578 -579 //----------------------------------------------------------------------- -580 /** -581 * Replaces all the occurrences of variables in the given source object with -582 * their matching values from the resolver. The input source object is -583 * converted to a string using <code>toString</code> and is not altered. -584 * -585 * @param source the source to replace in, null returns null -586 * @return the result of the replace operation -587 */ -588 public String replace(final Object source) { -589 if (source == null) { -590 return null; -591 } -592 final StrBuilder buf = new StrBuilder().append(source); -593 substitute(buf, 0, buf.length()); -594 return buf.toString(); -595 } -596 -597 //----------------------------------------------------------------------- -598 /** -599 * Replaces all the occurrences of variables within the given source buffer -600 * with their matching values from the resolver. -601 * The buffer is updated with the result. -602 * -603 * @param source the buffer to replace in, updated, null returns zero -604 * @return true if altered -605 */ -606 public boolean replaceIn(final StringBuffer source) { -607 if (source == null) { -608 return false; -609 } -610 return replaceIn(source, 0, source.length()); -611 } -612 -613 /** -614 * Replaces all the occurrences of variables within the given source buffer -615 * with their matching values from the resolver. -616 * The buffer is updated with the result. -617 * <p> -618 * Only the specified portion of the buffer will be processed. -619 * The rest of the buffer is not processed, but it is not deleted. -620 * -621 * @param source the buffer to replace in, updated, null returns zero -622 * @param offset the start offset within the array, must be valid -623 * @param length the length within the buffer to be processed, must be valid -624 * @return true if altered -625 */ -626 public boolean replaceIn(final StringBuffer source, final int offset, final int length) { -627 if (source == null) { -628 return false; -629 } -630 final StrBuilder buf = new StrBuilder(length).append(source, offset, length); -631 if (substitute(buf, 0, length) == false) { -632 return false; -633 } -634 source.replace(offset, offset + length, buf.toString()); -635 return true; -636 } -637 -638 //----------------------------------------------------------------------- -639 /** -640 * Replaces all the occurrences of variables within the given source buffer -641 * with their matching values from the resolver. -642 * The buffer is updated with the result. -643 * -644 * @param source the buffer to replace in, updated, null returns zero -645 * @return true if altered -646 */ -647 public boolean replaceIn(final StringBuilder source) { -648 if (source == null) { -649 return false; -650 } -651 return replaceIn(source, 0, source.length()); -652 } -653 -654 /** -655 * Replaces all the occurrences of variables within the given source builder -656 * with their matching values from the resolver. -657 * The builder is updated with the result. -658 * <p> -659 * Only the specified portion of the buffer will be processed. -660 * The rest of the buffer is not processed, but it is not deleted. -661 * -662 * @param source the buffer to replace in, updated, null returns zero -663 * @param offset the start offset within the array, must be valid -664 * @param length the length within the buffer to be processed, must be valid -665 * @return true if altered -666 */ -667 public boolean replaceIn(final StringBuilder source, final int offset, final int length) { -668 if (source == null) { -669 return false; -670 } -671 final StrBuilder buf = new StrBuilder(length).append(source, offset, length); -672 if (substitute(buf, 0, length) == false) { -673 return false; -674 } -675 source.replace(offset, offset + length, buf.toString()); -676 return true; -677 } -678 -679 //----------------------------------------------------------------------- -680 /** -681 * Replaces all the occurrences of variables within the given source -682 * builder with their matching values from the resolver. -683 * -684 * @param source the builder to replace in, updated, null returns zero -685 * @return true if altered -686 */ -687 public boolean replaceIn(final StrBuilder source) { -688 if (source == null) { -689 return false; -690 } -691 return substitute(source, 0, source.length()); -692 } -693 -694 /** -695 * Replaces all the occurrences of variables within the given source -696 * builder with their matching values from the resolver. -697 * <p> -698 * Only the specified portion of the builder will be processed. -699 * The rest of the builder is not processed, but it is not deleted. -700 * -701 * @param source the builder to replace in, null returns zero -702 * @param offset the start offset within the array, must be valid -703 * @param length the length within the builder to be processed, must be valid -704 * @return true if altered -705 */ -706 public boolean replaceIn(final StrBuilder source, final int offset, final int length) { -707 if (source == null) { -708 return false; -709 } -710 return substitute(source, offset, length); -711 } -712 -713 //----------------------------------------------------------------------- -714 /** -715 * Internal method that substitutes the variables. -716 * <p> -717 * Most users of this class do not need to call this method. This method will -718 * be called automatically by another (public) method. +198 public static <V> String replace(final Object source, +199 final Map<String, V> valueMap, +200 final String prefix, +201 final String suffix) { +202 return new StrSubstitutor(valueMap, prefix, suffix).replace(source); +203 } +204 +205 /** +206 * Replaces all the occurrences of variables in the given source object with their matching +207 * values from the properties. +208 * +209 * @param source the source text containing the variables to substitute, null returns null +210 * @param valueProperties the properties with values, may be null +211 * @return the result of the replace operation +212 */ +213 public static String replace(final Object source, final Properties valueProperties) { +214 if (valueProperties == null) { +215 return source.toString(); +216 } +217 final Map<String, String> valueMap = new HashMap<>(); +218 final Enumeration<?> propNames = valueProperties.propertyNames(); +219 while (propNames.hasMoreElements()) { +220 final String propName = (String) propNames.nextElement(); +221 final String propValue = valueProperties.getProperty(propName); +222 valueMap.put(propName, propValue); +223 } +224 return StrSubstitutor.replace(source, valueMap); +225 } +226 +227 /** +228 * Replaces all the occurrences of variables in the given source object with +229 * their matching values from the system properties. +230 * +231 * @param source the source text containing the variables to substitute, null returns null +232 * @return the result of the replace operation +233 */ +234 public static String replaceSystemProperties(final Object source) { +235 return new StrSubstitutor(StrLookup.systemPropertiesLookup()).replace(source); +236 } +237 +238 //----------------------------------------------------------------------- +239 /** +240 * Creates a new instance with defaults for variable prefix and suffix +241 * and the escaping character. +242 */ +243 public StrSubstitutor() { +244 this((StrLookup<?>) null, DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); +245 } +246 +247 /** +248 * Creates a new instance and initializes it. Uses defaults for variable +249 * prefix and suffix and the escaping character. +250 * +251 * @param <V> the type of the values in the map +252 * @param valueMap the map with the variables' values, may be null +253 */ +254 public <V> StrSubstitutor(final Map<String, V> valueMap) { +255 this(StrLookup.mapLookup(valueMap), DEFAULT_PREFIX, DEFAULT_SUFFIX, DEFAULT_ESCAPE); +256 } +257 +258 /** +259 * Creates a new instance and initializes it. Uses a default escaping character. +260 * +261 * @param <V> the type of the values in the map +262 * @param valueMap the map with the variables' values, may be null +263 * @param prefix the prefix for variables, not null +264 * @param suffix the suffix for variables, not null +265 * @throws IllegalArgumentException if the prefix or suffix is null +266 */ +267 public <V> StrSubstitutor(final Map<String, V> valueMap, final String prefix, final String suffix) { +268 this(StrLookup.mapLookup(valueMap), prefix, suffix, DEFAULT_ESCAPE); +269 } +270 +271 /** +272 * Creates a new instance and initializes it. [... 1432 lines stripped ...]