+// © 2016 and later: Unicode, Inc. and others.
+// License & terms of use: http://www.unicode.org/copyright.html
/*
*******************************************************************************
-* Copyright (C) 2011, International Business Machines
+* Copyright (C) 2011-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*******************************************************************************
* file name: messagepattern.cpp
-* encoding: US-ASCII
+* encoding: UTF-8
* tab size: 8 (not used)
* indentation:4
*
static const UChar u_equal=0x3D;
static const UChar u_A=0x41;
static const UChar u_C=0x43;
+static const UChar u_D=0x44;
static const UChar u_E=0x45;
static const UChar u_H=0x48;
static const UChar u_I=0x49;
static const UChar u_L=0x4C;
+static const UChar u_N=0x4E;
static const UChar u_O=0x4F;
static const UChar u_P=0x50;
static const UChar u_R=0x52;
static const UChar u_Z=0x5A;
static const UChar u_a=0x61;
static const UChar u_c=0x63;
+static const UChar u_d=0x64;
static const UChar u_e=0x65;
static const UChar u_f=0x66;
static const UChar u_h=0x68;
static const UChar u_i=0x69;
static const UChar u_l=0x6C;
+static const UChar u_n=0x6E;
static const UChar u_o=0x6F;
static const UChar u_p=0x70;
static const UChar u_r=0x72;
int32_t length,
UErrorCode &errorCode);
UBool ensureCapacityForOneMore(int32_t oldLength, UErrorCode &errorCode);
- UBool memEquals(const MessagePatternList<T, stackCapacity> &other, int32_t length) const {
- return 0==uprv_memcmp(a.getAlias(), other.a.getAlias(), length*sizeof(T));
+ UBool equals(const MessagePatternList<T, stackCapacity> &other, int32_t length) const {
+ for(int32_t i=0; i<length; ++i) {
+ if(a[i]!=other.a[i]) { return FALSE; }
+ }
+ return TRUE;
}
MaybeStackArray<T, stackCapacity> a;
errorCode=U_MEMORY_ALLOCATION_ERROR;
return;
}
- uprv_memcpy(a.getAlias(), other.a.getAlias(), length*sizeof(T));
+ uprv_memcpy(a.getAlias(), other.a.getAlias(), (size_t)length*sizeof(T));
}
}
}
MessagePattern::MessagePattern(const MessagePattern &other)
- : aposMode(other.aposMode), msg(other.msg),
+ : UObject(other), aposMode(other.aposMode), msg(other.msg),
partsList(NULL), parts(NULL), partsLength(0),
numericValuesList(NULL), numericValues(NULL), numericValuesLength(0),
hasArgNames(other.hasArgNames), hasArgNumbers(other.hasArgNumbers),
msg==other.msg &&
// parts.equals(o.parts)
partsLength==other.partsLength &&
- (partsLength==0 || partsList->memEquals(*other.partsList, partsLength));
+ (partsLength==0 || partsList->equals(*other.partsList, partsLength));
// No need to compare numericValues if msg and parts are the same.
}
aposMode==UMSGPAT_APOS_DOUBLE_REQUIRED ||
c==u_leftCurlyBrace || c==u_rightCurlyBrace ||
(parentType==UMSGPAT_ARG_TYPE_CHOICE && c==u_pipe) ||
- (parentType==UMSGPAT_ARG_TYPE_PLURAL && c==u_pound)
+ (UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(parentType) && c==u_pound)
) {
// skip the quote-starting apostrophe
addPart(UMSGPAT_PART_TYPE_SKIP_SYNTAX, index-1, 1, 0, errorCode);
needsAutoQuoting=TRUE;
}
}
- } else if(parentType==UMSGPAT_ARG_TYPE_PLURAL && c==u_pound) {
+ } else if(UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(parentType) && c==u_pound) {
// The unquoted # in a plural message fragment will be replaced
// with the (number-offset).
addPart(UMSGPAT_PART_TYPE_REPLACE_NUMBER, index-1, 1, 0, errorCode);
} else if(isSelect(typeIndex)) {
argType=UMSGPAT_ARG_TYPE_SELECT;
}
+ } else if(length==13) {
+ if(isSelect(typeIndex) && isOrdinal(typeIndex+6)) {
+ argType=UMSGPAT_ARG_TYPE_SELECTORDINAL;
+ }
}
// change the ARG_START type from NONE to argType
partsList->a[argStart].value=(int16_t)argType;
return index;
}
int32_t selectorIndex=index;
- if(argType==UMSGPAT_ARG_TYPE_PLURAL && msg.charAt(selectorIndex)==u_equal) {
+ if(UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType) && msg.charAt(selectorIndex)==u_equal) {
// explicit-value plural selector: =double
index=skipDouble(index+1);
int32_t length=index-selectorIndex;
return 0;
}
// Note: The ':' in "offset:" is just beyond the skipIdentifier() range.
- if( argType==UMSGPAT_ARG_TYPE_PLURAL && length==6 && index<msg.length() &&
+ if( UMSGPAT_ARG_TYPE_HAS_PLURAL_STYLE(argType) && length==6 && index<msg.length() &&
0==msg.compare(selectorIndex, 7, kOffsetColon, 0, 7)
) {
// plural offset, not a selector
((c=msg.charAt(index))==u_t || c==u_T);
}
+UBool
+MessagePattern::isOrdinal(int32_t index) {
+ UChar c;
+ return
+ ((c=msg.charAt(index++))==u_o || c==u_O) &&
+ ((c=msg.charAt(index++))==u_r || c==u_R) &&
+ ((c=msg.charAt(index++))==u_d || c==u_D) &&
+ ((c=msg.charAt(index++))==u_i || c==u_I) &&
+ ((c=msg.charAt(index++))==u_n || c==u_N) &&
+ ((c=msg.charAt(index++))==u_a || c==u_A) &&
+ ((c=msg.charAt(index))==u_l || c==u_L);
+}
+
UBool
MessagePattern::inMessageFormatPattern(int32_t nestingLevel) {
return nestingLevel>0 || partsList->a[0].type==UMSGPAT_PART_TYPE_MSG_START;
parseError->postContext[length]=0;
}
-UOBJECT_DEFINE_NO_RTTI_IMPLEMENTATION(MessagePattern)
-
// MessageImpl ------------------------------------------------------------- ***
void