intl/icu/source/common/uset_props.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/common/uset_props.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,141 @@
     1.4 +/*
     1.5 +*******************************************************************************
     1.6 +*
     1.7 +*   Copyright (C) 2002-2011, International Business Machines
     1.8 +*   Corporation and others.  All Rights Reserved.
     1.9 +*
    1.10 +*******************************************************************************
    1.11 +*   file name:  uset_props.cpp
    1.12 +*   encoding:   US-ASCII
    1.13 +*   tab size:   8 (not used)
    1.14 +*   indentation:4
    1.15 +*
    1.16 +*   created on: 2004aug30
    1.17 +*   created by: Markus W. Scherer
    1.18 +*
    1.19 +*   C wrappers around UnicodeSet functions that are implemented in
    1.20 +*   uniset_props.cpp, split off for modularization.
    1.21 +*/
    1.22 +
    1.23 +#include "unicode/utypes.h"
    1.24 +#include "unicode/uobject.h"
    1.25 +#include "unicode/uset.h"
    1.26 +#include "unicode/uniset.h"
    1.27 +#include "cmemory.h"
    1.28 +#include "unicode/ustring.h"
    1.29 +#include "unicode/parsepos.h"
    1.30 +
    1.31 +U_NAMESPACE_USE
    1.32 +
    1.33 +U_CAPI USet* U_EXPORT2
    1.34 +uset_openPattern(const UChar* pattern, int32_t patternLength,
    1.35 +                 UErrorCode* ec)
    1.36 +{
    1.37 +    UnicodeString pat(patternLength==-1, pattern, patternLength);
    1.38 +    UnicodeSet* set = new UnicodeSet(pat, *ec);
    1.39 +    /* test for NULL */
    1.40 +    if(set == 0) {
    1.41 +        *ec = U_MEMORY_ALLOCATION_ERROR;
    1.42 +        return 0;
    1.43 +    }
    1.44 +
    1.45 +    if (U_FAILURE(*ec)) {
    1.46 +        delete set;
    1.47 +        set = NULL;
    1.48 +    }
    1.49 +    return (USet*) set;
    1.50 +}
    1.51 +
    1.52 +U_CAPI USet* U_EXPORT2
    1.53 +uset_openPatternOptions(const UChar* pattern, int32_t patternLength,
    1.54 +                 uint32_t options,
    1.55 +                 UErrorCode* ec)
    1.56 +{
    1.57 +    UnicodeString pat(patternLength==-1, pattern, patternLength);
    1.58 +    UnicodeSet* set = new UnicodeSet(pat, options, NULL, *ec);
    1.59 +    /* test for NULL */
    1.60 +    if(set == 0) {
    1.61 +        *ec = U_MEMORY_ALLOCATION_ERROR;
    1.62 +        return 0;
    1.63 +    }
    1.64 +
    1.65 +    if (U_FAILURE(*ec)) {
    1.66 +        delete set;
    1.67 +        set = NULL;
    1.68 +    }
    1.69 +    return (USet*) set;
    1.70 +}
    1.71 +
    1.72 +
    1.73 +U_CAPI int32_t U_EXPORT2 
    1.74 +uset_applyPattern(USet *set,
    1.75 +                  const UChar *pattern, int32_t patternLength,
    1.76 +                  uint32_t options,
    1.77 +                  UErrorCode *status){
    1.78 +
    1.79 +    // status code needs to be checked since we 
    1.80 +    // dereference it
    1.81 +    if(status == NULL || U_FAILURE(*status)){
    1.82 +        return 0;
    1.83 +    }
    1.84 +
    1.85 +    // check only the set paramenter
    1.86 +    // if pattern is NULL or null terminate
    1.87 +    // UnicodeString constructor takes care of it
    1.88 +    if(set == NULL){
    1.89 +        *status = U_ILLEGAL_ARGUMENT_ERROR;
    1.90 +        return 0;
    1.91 +    }
    1.92 +
    1.93 +    UnicodeString pat(pattern, patternLength);
    1.94 +
    1.95 +    ParsePosition pos;
    1.96 +   
    1.97 +    ((UnicodeSet*) set)->applyPattern(pat, pos, options, NULL, *status);
    1.98 +    
    1.99 +    return pos.getIndex();
   1.100 +}
   1.101 +
   1.102 +U_CAPI void U_EXPORT2
   1.103 +uset_applyIntPropertyValue(USet* set,
   1.104 +               UProperty prop, int32_t value, UErrorCode* ec) {
   1.105 +    ((UnicodeSet*) set)->applyIntPropertyValue(prop, value, *ec);
   1.106 +}
   1.107 +
   1.108 +U_CAPI void U_EXPORT2
   1.109 +uset_applyPropertyAlias(USet* set,
   1.110 +                        const UChar *prop, int32_t propLength,
   1.111 +                        const UChar *value, int32_t valueLength,
   1.112 +            UErrorCode* ec) {
   1.113 +
   1.114 +    UnicodeString p(prop, propLength);
   1.115 +    UnicodeString v(value, valueLength);
   1.116 +
   1.117 +    ((UnicodeSet*) set)->applyPropertyAlias(p, v, *ec);
   1.118 +}
   1.119 +
   1.120 +U_CAPI UBool U_EXPORT2
   1.121 +uset_resemblesPattern(const UChar *pattern, int32_t patternLength,
   1.122 +                      int32_t pos) {
   1.123 +
   1.124 +    UnicodeString pat(pattern, patternLength);
   1.125 +
   1.126 +    return ((pos+1) < pat.length() &&
   1.127 +            pat.charAt(pos) == (UChar)91/*[*/) ||
   1.128 +            UnicodeSet::resemblesPattern(pat, pos);
   1.129 +}
   1.130 +
   1.131 +U_CAPI int32_t U_EXPORT2
   1.132 +uset_toPattern(const USet* set,
   1.133 +               UChar* result, int32_t resultCapacity,
   1.134 +               UBool escapeUnprintable,
   1.135 +               UErrorCode* ec) {
   1.136 +    UnicodeString pat;
   1.137 +    ((const UnicodeSet*) set)->toPattern(pat, escapeUnprintable);
   1.138 +    return pat.extract(result, resultCapacity, *ec);
   1.139 +}
   1.140 +
   1.141 +U_CAPI void U_EXPORT2
   1.142 +uset_closeOver(USet* set, int32_t attributes) {
   1.143 +    ((UnicodeSet*) set)->UnicodeSet::closeOver(attributes);
   1.144 +}

mercurial