Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Unified Diff: source/common/simplepatternformatter.h

Issue 1621843002: ICU 56 update step 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/icu.git@561
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « source/common/sharedobject.cpp ('k') | source/common/simplepatternformatter.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: source/common/simplepatternformatter.h
diff --git a/source/common/simplepatternformatter.h b/source/common/simplepatternformatter.h
index b286a79cc35821a254041b75090e1c580245e9c2..6740dc9f47b27c0da747d09762b476ddf011200c 100644
--- a/source/common/simplepatternformatter.h
+++ b/source/common/simplepatternformatter.h
@@ -17,6 +17,8 @@
U_NAMESPACE_BEGIN
+class SimplePatternFormatterPlaceholderValues;
+
struct PlaceholderInfo {
int32_t id;
int32_t offset;
@@ -39,7 +41,7 @@ struct PlaceholderInfo {
* UnicodeString result;
* UErrorCode status = U_ZERO_ERROR;
* // Evaluates to: "paul {born} in england"
- * fmt.format("englad", "paul", result, status);
+ * fmt.format("england", "paul", result, status);
* </pre>
*/
class U_COMMON_API SimplePatternFormatter : public UMemory {
@@ -91,12 +93,6 @@ public:
}
/**
- * Returns true if the pattern this object represents starts with
- * placeholder id; otherwise, returns false.
- */
- UBool startsWithPlaceholder(int32_t id) const;
-
- /**
* Returns this pattern with none of the placeholders.
*/
const UnicodeString &getPatternWithNoPlaceholders() const {
@@ -104,7 +100,7 @@ public:
}
/**
- * Formats given value.
+ * Formats given value. arg0 cannot be appendTo.
*/
UnicodeString &format(
const UnicodeString &args0,
@@ -112,7 +108,7 @@ public:
UErrorCode &status) const;
/**
- * Formats given values.
+ * Formats given values. Neither arg0 nor arg1 can be appendTo.
*/
UnicodeString &format(
const UnicodeString &args0,
@@ -121,7 +117,7 @@ public:
UErrorCode &status) const;
/**
- * Formats given values.
+ * Formats given values. Neither arg0, arg1, nor arg2 can be appendTo.
*/
UnicodeString &format(
const UnicodeString &args0,
@@ -135,37 +131,82 @@ public:
*
* The caller retains ownership of all pointers.
* @param placeholderValues 1st one corresponds to {0}; 2nd to {1};
- * 3rd to {2} etc.
+ * 3rd to {2} etc. If any of these point to appendTo, this method
+ * sets status to U_ILLEGAL_ARGUMENT_ERROR.
* @param placeholderValueCount the number of placeholder values
* must be at least large enough to provide values for all placeholders
* in this object. Otherwise status set to U_ILLEGAL_ARGUMENT_ERROR.
- * @param appendTo resulting string appended here. Optimization: If
- * the pattern this object represents starts with a placeholder AND
- * appendTo references the value of that same placeholder, then that
- * placeholder value is not copied to appendTo (Its already there).
- * If the value of the starting placeholder is a very large string,
- * this optimization can offer huge savings.
+ * @param appendTo resulting string appended here.
* @param offsetArray The offset of each placeholder value in appendTo
* stored here. The first value gets the offset of the value for {0};
* the 2nd for {1}; the 3rd for {2} etc. -1 means that the corresponding
* placeholder does not exist in this object. If caller is not
* interested in offsets, it may pass NULL and 0 for the length.
- * @param offsetArrayLength the size of offsetArray may be less than
- * placeholderValueCount.
+ * @param offsetArrayLength the size of offsetArray. If less than
+ * placeholderValueCount only the first offsets get recorded. If
+ * greater than placeholderValueCount, then extra values in offset
+ * array are set to -1.
* @param status any error stored here.
*/
- UnicodeString &format(
+ UnicodeString &formatAndAppend(
const UnicodeString * const *placeholderValues,
int32_t placeholderValueCount,
UnicodeString &appendTo,
int32_t *offsetArray,
int32_t offsetArrayLength,
UErrorCode &status) const;
+
+ /**
+ * Formats given values.
+ *
+ * The caller retains ownership of all pointers.
+ * @param placeholderValues 1st one corresponds to {0}; 2nd to {1};
+ * 3rd to {2} etc. May include pointer to result in which case
+ * the previous value of result is used for the corresponding
+ * placeholder.
+ * @param placeholderValueCount the number of placeholder values
+ * must be at least large enough to provide values for all placeholders
+ * in this object. Otherwise status set to U_ILLEGAL_ARGUMENT_ERROR.
+ * @param result resulting string stored here overwriting any previous
+ * value.
+ * @param offsetArray The offset of each placeholder value in result
+ * stored here. The first value gets the offset of the value for {0};
+ * the 2nd for {1}; the 3rd for {2} etc. -1 means that the corresponding
+ * placeholder does not exist in this object. If caller is not
+ * interested in offsets, it may pass NULL and 0 for the length.
+ * @param offsetArrayLength the size of offsetArray. If less than
+ * placeholderValueCount only the first offsets get recorded. If
+ * greater than placeholderValueCount, then extra values in offset
+ * array are set to -1.
+ * @param status any error stored here.
+ */
+ UnicodeString &formatAndReplace(
+ const UnicodeString * const *placeholderValues,
+ int32_t placeholderValueCount,
+ UnicodeString &result,
+ int32_t *offsetArray,
+ int32_t offsetArrayLength,
+ UErrorCode &status) const;
private:
UnicodeString noPlaceholders;
MaybeStackArray<PlaceholderInfo, 3> placeholders;
int32_t placeholderSize;
int32_t placeholderCount;
+ UBool firstPlaceholderReused;
+
+ // A Placeholder value that is the same as appendTo is treated as the
+ // empty string.
+ UnicodeString &formatAndAppend(
+ const SimplePatternFormatterPlaceholderValues &placeholderValues,
+ UnicodeString &appendTo,
+ int32_t *offsetArray,
+ int32_t offsetArrayLength) const;
+
+ // Returns the placeholder at the beginning of this pattern
+ // (e.g 3 for placeholder {3}). Returns -1 if the beginning of pattern
+ // is text or if the placeholder at the beginning of this pattern
+ // is used again in the middle of the pattern.
+ int32_t getUniquePlaceholderAtStart() const;
// ensureCapacity ensures that the capacity of the placeholders array
// is desiredCapacity. If ensureCapacity must resize the placeholders
« no previous file with comments | « source/common/sharedobject.cpp ('k') | source/common/simplepatternformatter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698