00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef FORMAT_H
00021 #define FORMAT_H
00022
00023
00024 #include "unicode/utypes.h"
00025 #include "unicode/unistr.h"
00026 #include "unicode/fmtable.h"
00027 #include "unicode/fieldpos.h"
00028 #include "unicode/parsepos.h"
00029 #include "unicode/parseerr.h"
00030
00031 U_NAMESPACE_BEGIN
00086 class U_I18N_API Format {
00087 public:
00088
00089 virtual ~Format();
00090
00096 virtual UBool operator==(const Format& other) const = 0;
00097
00103 UBool operator!=(const Format& other) const { return !operator==(other); }
00104
00110 virtual Format* clone() const = 0;
00111
00122 UnicodeString& format(const Formattable& obj,
00123 UnicodeString& result,
00124 UErrorCode& status) const;
00125
00142 virtual UnicodeString& format(const Formattable& obj,
00143 UnicodeString& toAppendTo,
00144 FieldPosition& pos,
00145 UErrorCode& status) const = 0;
00146
00186 virtual void parseObject(const UnicodeString& source,
00187 Formattable& result,
00188 ParsePosition& parse_pos) const = 0;
00189
00202 void parseObject(const UnicodeString& source,
00203 Formattable& result,
00204 UErrorCode& status) const;
00205
00223 virtual UClassID getDynamicClassID() const = 0;
00224
00225 protected:
00230 Format();
00231
00235 Format(const Format&);
00236
00240 Format& operator=(const Format&);
00241
00242
00243 inline void syntaxError(const UnicodeString& pattern,
00244 int32_t pos,
00245 UParseError& parseError){
00246 parseError.offset = pos;
00247 parseError.line=0;
00248
00249
00250 int32_t start = (pos <=U_PARSE_CONTEXT_LEN)? 0 : (pos - (U_PARSE_CONTEXT_LEN-1
00251 ));
00252 int32_t stop = pos;
00253 pattern.extract(start,stop-start,parseError.preContext,0);
00254
00255 parseError.preContext[stop-start] = 0;
00256
00257
00258 start = pos+1;
00259 stop = ((pos+U_PARSE_CONTEXT_LEN)<=pattern.length()) ? (pos+(U_PARSE_CONTEXT_LEN-1)) :
00260 pattern.length();
00261 pattern.extract(start,stop-start,parseError.postContext,0);
00262
00263 parseError.postContext[stop-start]= 0;
00264 }
00265 };
00266
00267 U_NAMESPACE_END
00268
00269 #endif // _FORMAT
00270