michael@0: /* michael@0: ******************************************************************************* michael@0: * michael@0: * Copyright (C) 2002-2011, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ******************************************************************************* michael@0: * file name: uset_props.cpp michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2004aug30 michael@0: * created by: Markus W. Scherer michael@0: * michael@0: * C wrappers around UnicodeSet functions that are implemented in michael@0: * uniset_props.cpp, split off for modularization. michael@0: */ michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uobject.h" michael@0: #include "unicode/uset.h" michael@0: #include "unicode/uniset.h" michael@0: #include "cmemory.h" michael@0: #include "unicode/ustring.h" michael@0: #include "unicode/parsepos.h" michael@0: michael@0: U_NAMESPACE_USE michael@0: michael@0: U_CAPI USet* U_EXPORT2 michael@0: uset_openPattern(const UChar* pattern, int32_t patternLength, michael@0: UErrorCode* ec) michael@0: { michael@0: UnicodeString pat(patternLength==-1, pattern, patternLength); michael@0: UnicodeSet* set = new UnicodeSet(pat, *ec); michael@0: /* test for NULL */ michael@0: if(set == 0) { michael@0: *ec = U_MEMORY_ALLOCATION_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: if (U_FAILURE(*ec)) { michael@0: delete set; michael@0: set = NULL; michael@0: } michael@0: return (USet*) set; michael@0: } michael@0: michael@0: U_CAPI USet* U_EXPORT2 michael@0: uset_openPatternOptions(const UChar* pattern, int32_t patternLength, michael@0: uint32_t options, michael@0: UErrorCode* ec) michael@0: { michael@0: UnicodeString pat(patternLength==-1, pattern, patternLength); michael@0: UnicodeSet* set = new UnicodeSet(pat, options, NULL, *ec); michael@0: /* test for NULL */ michael@0: if(set == 0) { michael@0: *ec = U_MEMORY_ALLOCATION_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: if (U_FAILURE(*ec)) { michael@0: delete set; michael@0: set = NULL; michael@0: } michael@0: return (USet*) set; michael@0: } michael@0: michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uset_applyPattern(USet *set, michael@0: const UChar *pattern, int32_t patternLength, michael@0: uint32_t options, michael@0: UErrorCode *status){ michael@0: michael@0: // status code needs to be checked since we michael@0: // dereference it michael@0: if(status == NULL || U_FAILURE(*status)){ michael@0: return 0; michael@0: } michael@0: michael@0: // check only the set paramenter michael@0: // if pattern is NULL or null terminate michael@0: // UnicodeString constructor takes care of it michael@0: if(set == NULL){ michael@0: *status = U_ILLEGAL_ARGUMENT_ERROR; michael@0: return 0; michael@0: } michael@0: michael@0: UnicodeString pat(pattern, patternLength); michael@0: michael@0: ParsePosition pos; michael@0: michael@0: ((UnicodeSet*) set)->applyPattern(pat, pos, options, NULL, *status); michael@0: michael@0: return pos.getIndex(); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: uset_applyIntPropertyValue(USet* set, michael@0: UProperty prop, int32_t value, UErrorCode* ec) { michael@0: ((UnicodeSet*) set)->applyIntPropertyValue(prop, value, *ec); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: uset_applyPropertyAlias(USet* set, michael@0: const UChar *prop, int32_t propLength, michael@0: const UChar *value, int32_t valueLength, michael@0: UErrorCode* ec) { michael@0: michael@0: UnicodeString p(prop, propLength); michael@0: UnicodeString v(value, valueLength); michael@0: michael@0: ((UnicodeSet*) set)->applyPropertyAlias(p, v, *ec); michael@0: } michael@0: michael@0: U_CAPI UBool U_EXPORT2 michael@0: uset_resemblesPattern(const UChar *pattern, int32_t patternLength, michael@0: int32_t pos) { michael@0: michael@0: UnicodeString pat(pattern, patternLength); michael@0: michael@0: return ((pos+1) < pat.length() && michael@0: pat.charAt(pos) == (UChar)91/*[*/) || michael@0: UnicodeSet::resemblesPattern(pat, pos); michael@0: } michael@0: michael@0: U_CAPI int32_t U_EXPORT2 michael@0: uset_toPattern(const USet* set, michael@0: UChar* result, int32_t resultCapacity, michael@0: UBool escapeUnprintable, michael@0: UErrorCode* ec) { michael@0: UnicodeString pat; michael@0: ((const UnicodeSet*) set)->toPattern(pat, escapeUnprintable); michael@0: return pat.extract(result, resultCapacity, *ec); michael@0: } michael@0: michael@0: U_CAPI void U_EXPORT2 michael@0: uset_closeOver(USet* set, int32_t attributes) { michael@0: ((UnicodeSet*) set)->UnicodeSet::closeOver(attributes); michael@0: }