intl/icu/source/common/uset_props.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 *******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 2002-2011, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 *******************************************************************************
michael@0 8 * file name: uset_props.cpp
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 2004aug30
michael@0 14 * created by: Markus W. Scherer
michael@0 15 *
michael@0 16 * C wrappers around UnicodeSet functions that are implemented in
michael@0 17 * uniset_props.cpp, split off for modularization.
michael@0 18 */
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21 #include "unicode/uobject.h"
michael@0 22 #include "unicode/uset.h"
michael@0 23 #include "unicode/uniset.h"
michael@0 24 #include "cmemory.h"
michael@0 25 #include "unicode/ustring.h"
michael@0 26 #include "unicode/parsepos.h"
michael@0 27
michael@0 28 U_NAMESPACE_USE
michael@0 29
michael@0 30 U_CAPI USet* U_EXPORT2
michael@0 31 uset_openPattern(const UChar* pattern, int32_t patternLength,
michael@0 32 UErrorCode* ec)
michael@0 33 {
michael@0 34 UnicodeString pat(patternLength==-1, pattern, patternLength);
michael@0 35 UnicodeSet* set = new UnicodeSet(pat, *ec);
michael@0 36 /* test for NULL */
michael@0 37 if(set == 0) {
michael@0 38 *ec = U_MEMORY_ALLOCATION_ERROR;
michael@0 39 return 0;
michael@0 40 }
michael@0 41
michael@0 42 if (U_FAILURE(*ec)) {
michael@0 43 delete set;
michael@0 44 set = NULL;
michael@0 45 }
michael@0 46 return (USet*) set;
michael@0 47 }
michael@0 48
michael@0 49 U_CAPI USet* U_EXPORT2
michael@0 50 uset_openPatternOptions(const UChar* pattern, int32_t patternLength,
michael@0 51 uint32_t options,
michael@0 52 UErrorCode* ec)
michael@0 53 {
michael@0 54 UnicodeString pat(patternLength==-1, pattern, patternLength);
michael@0 55 UnicodeSet* set = new UnicodeSet(pat, options, NULL, *ec);
michael@0 56 /* test for NULL */
michael@0 57 if(set == 0) {
michael@0 58 *ec = U_MEMORY_ALLOCATION_ERROR;
michael@0 59 return 0;
michael@0 60 }
michael@0 61
michael@0 62 if (U_FAILURE(*ec)) {
michael@0 63 delete set;
michael@0 64 set = NULL;
michael@0 65 }
michael@0 66 return (USet*) set;
michael@0 67 }
michael@0 68
michael@0 69
michael@0 70 U_CAPI int32_t U_EXPORT2
michael@0 71 uset_applyPattern(USet *set,
michael@0 72 const UChar *pattern, int32_t patternLength,
michael@0 73 uint32_t options,
michael@0 74 UErrorCode *status){
michael@0 75
michael@0 76 // status code needs to be checked since we
michael@0 77 // dereference it
michael@0 78 if(status == NULL || U_FAILURE(*status)){
michael@0 79 return 0;
michael@0 80 }
michael@0 81
michael@0 82 // check only the set paramenter
michael@0 83 // if pattern is NULL or null terminate
michael@0 84 // UnicodeString constructor takes care of it
michael@0 85 if(set == NULL){
michael@0 86 *status = U_ILLEGAL_ARGUMENT_ERROR;
michael@0 87 return 0;
michael@0 88 }
michael@0 89
michael@0 90 UnicodeString pat(pattern, patternLength);
michael@0 91
michael@0 92 ParsePosition pos;
michael@0 93
michael@0 94 ((UnicodeSet*) set)->applyPattern(pat, pos, options, NULL, *status);
michael@0 95
michael@0 96 return pos.getIndex();
michael@0 97 }
michael@0 98
michael@0 99 U_CAPI void U_EXPORT2
michael@0 100 uset_applyIntPropertyValue(USet* set,
michael@0 101 UProperty prop, int32_t value, UErrorCode* ec) {
michael@0 102 ((UnicodeSet*) set)->applyIntPropertyValue(prop, value, *ec);
michael@0 103 }
michael@0 104
michael@0 105 U_CAPI void U_EXPORT2
michael@0 106 uset_applyPropertyAlias(USet* set,
michael@0 107 const UChar *prop, int32_t propLength,
michael@0 108 const UChar *value, int32_t valueLength,
michael@0 109 UErrorCode* ec) {
michael@0 110
michael@0 111 UnicodeString p(prop, propLength);
michael@0 112 UnicodeString v(value, valueLength);
michael@0 113
michael@0 114 ((UnicodeSet*) set)->applyPropertyAlias(p, v, *ec);
michael@0 115 }
michael@0 116
michael@0 117 U_CAPI UBool U_EXPORT2
michael@0 118 uset_resemblesPattern(const UChar *pattern, int32_t patternLength,
michael@0 119 int32_t pos) {
michael@0 120
michael@0 121 UnicodeString pat(pattern, patternLength);
michael@0 122
michael@0 123 return ((pos+1) < pat.length() &&
michael@0 124 pat.charAt(pos) == (UChar)91/*[*/) ||
michael@0 125 UnicodeSet::resemblesPattern(pat, pos);
michael@0 126 }
michael@0 127
michael@0 128 U_CAPI int32_t U_EXPORT2
michael@0 129 uset_toPattern(const USet* set,
michael@0 130 UChar* result, int32_t resultCapacity,
michael@0 131 UBool escapeUnprintable,
michael@0 132 UErrorCode* ec) {
michael@0 133 UnicodeString pat;
michael@0 134 ((const UnicodeSet*) set)->toPattern(pat, escapeUnprintable);
michael@0 135 return pat.extract(result, resultCapacity, *ec);
michael@0 136 }
michael@0 137
michael@0 138 U_CAPI void U_EXPORT2
michael@0 139 uset_closeOver(USet* set, int32_t attributes) {
michael@0 140 ((UnicodeSet*) set)->UnicodeSet::closeOver(attributes);
michael@0 141 }

mercurial