mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-14 17:24:01 +00:00
ICU-8745 docs & comments from code review
X-SVN-Rev: 30533
This commit is contained in:
parent
c801179c8d
commit
6a3384cfa2
3 changed files with 35 additions and 10 deletions
|
@ -11,6 +11,7 @@ package com.ibm.icu.dev.demo.messagepattern;
|
|||
|
||||
import com.ibm.icu.text.MessagePattern;
|
||||
import com.ibm.icu.text.MessagePatternUtil;
|
||||
import com.ibm.icu.text.MessagePatternUtil.VariantNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -73,7 +74,8 @@ public class MessagePatternUtilDemo {
|
|||
double value;
|
||||
switch (argType) {
|
||||
case CHOICE:
|
||||
System.out.println(indent + variant.getSelectorValue() + " " + variant.getSelector() + ":");
|
||||
System.out.println(indent + variant.getSelectorValue() + " " +
|
||||
variant.getSelector() + ":");
|
||||
break;
|
||||
case PLURAL:
|
||||
value = variant.getSelectorValue();
|
||||
|
@ -189,7 +191,8 @@ public class MessagePatternUtilDemo {
|
|||
if (!keywordVariants.isEmpty()) {
|
||||
System.out.println(manySpaces.substring(0, depth * 2) +
|
||||
"_keyword = PluralRules.select(" + pluralNumber + ")");
|
||||
genCodeForKeywordVariants(keywordVariants, depth++, firstResult, "_keyword", pluralNumber);
|
||||
genCodeForKeywordVariants(keywordVariants, depth++, firstResult,
|
||||
"_keyword", pluralNumber);
|
||||
}
|
||||
genCode(otherVariant.getMessage(), depth, firstResult, pluralNumber);
|
||||
if (origDepth < depth) {
|
||||
|
@ -216,7 +219,7 @@ public class MessagePatternUtilDemo {
|
|||
}
|
||||
}
|
||||
|
||||
private static final void genCodeForNumericVariants(List<MessagePatternUtil.VariantNode> variants,
|
||||
private static final void genCodeForNumericVariants(List<VariantNode> variants,
|
||||
int depth,
|
||||
boolean firstResult,
|
||||
String varName,
|
||||
|
@ -234,7 +237,7 @@ public class MessagePatternUtilDemo {
|
|||
System.out.println(indent + "} else {");
|
||||
}
|
||||
|
||||
private static final void genCodeForKeywordVariants(List<MessagePatternUtil.VariantNode> variants,
|
||||
private static final void genCodeForKeywordVariants(List<VariantNode> variants,
|
||||
int depth,
|
||||
boolean firstResult,
|
||||
String varName,
|
||||
|
@ -334,9 +337,10 @@ public class MessagePatternUtilDemo {
|
|||
msg="_'__{gender, select, female{Her n'ame is {person_name}.}"+
|
||||
"other{His n'ame is {person_name}.}}__'_";
|
||||
print(msg);
|
||||
print("{num,plural,offset:1 =0{no one} =1{one, that is one and # others} " +
|
||||
"one{one and # (probably 1) others} few{one and # others} " +
|
||||
"other{lots & lots}}");
|
||||
print("{num,plural,offset:1 " +
|
||||
"=0{no one} =1{one, that is one and # others} " +
|
||||
"one{one and # (probably 1) others} few{one and # others} " +
|
||||
"other{lots & lots}}");
|
||||
print(
|
||||
"{p1_gender,select," +
|
||||
"female{" +
|
||||
|
|
|
@ -20,6 +20,9 @@ import java.util.List;
|
|||
* Intended for use in tools when convenience is more important than
|
||||
* minimizing runtime and object creations.
|
||||
*
|
||||
* <p>This class only has static methods.
|
||||
* Each of the nested classes is immutable and thread-safe.
|
||||
*
|
||||
* <p>This class and its nested classes are not intended for public subclassing.
|
||||
* @draft ICU 49
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
|
@ -62,6 +65,7 @@ public final class MessagePatternUtil {
|
|||
/**
|
||||
* Common base class for all elements in a tree of nodes
|
||||
* returned by {@link MessagePatternUtil#buildMessageNode(MessagePattern)}.
|
||||
* This class and all subclasses are immutable and thread-safe.
|
||||
* @draft ICU 49
|
||||
* @provisional This API might change or be removed in a future release.
|
||||
*/
|
||||
|
@ -165,6 +169,10 @@ public final class MessagePatternUtil {
|
|||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// Note: There is no specific subclass for REPLACE_NUMBER
|
||||
// because it would not provide any additional API.
|
||||
// Therefore we have a little bit of REPLACE_NUMBER-specific code
|
||||
// here in the contents-node base class.
|
||||
return "{REPLACE_NUMBER}";
|
||||
}
|
||||
|
||||
|
|
|
@ -15,11 +15,11 @@ import java.util.List;
|
|||
|
||||
import com.ibm.icu.text.MessagePattern;
|
||||
import com.ibm.icu.text.MessagePatternUtil;
|
||||
import com.ibm.icu.text.MessagePatternUtil.MessageNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.MessageContentsNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.TextNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.ArgNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.ComplexArgStyleNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.MessageContentsNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.MessageNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.TextNode;
|
||||
import com.ibm.icu.text.MessagePatternUtil.VariantNode;
|
||||
|
||||
/**
|
||||
|
@ -379,6 +379,19 @@ public final class MessagePatternUtilTest extends com.ibm.icu.dev.test.TestFmwk
|
|||
finishComplexArg().
|
||||
expectTextThatContains("_z");
|
||||
expect.checkMatches(msg);
|
||||
// Plural with explicit offset:0.
|
||||
msg = MessagePatternUtil.buildMessageNode(
|
||||
"a_{0,plural,offset:0 other{num=#!}}_z");
|
||||
expect = new ExpectMessageNode().
|
||||
expectTextThatContains("a_").
|
||||
expectPluralArg(0).
|
||||
expectOffset(0).
|
||||
expectVariant("other").
|
||||
expectTextThatContains("num=").expectReplaceNumber().
|
||||
expectTextThatContains("!").finishVariant().
|
||||
finishComplexArg().
|
||||
expectTextThatContains("_z");
|
||||
expect.checkMatches(msg);
|
||||
}
|
||||
|
||||
public void TestChoiceArg() {
|
||||
|
|
Loading…
Add table
Reference in a new issue