2020-08-11 11:10:23 +02:00
|
|
|
// © 2016 and later: Unicode, Inc. and others.
|
|
|
|
// License & terms of use: http://www.unicode.org/copyright.html
|
|
|
|
/*
|
|
|
|
*******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002-2011, International Business Machines
|
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
|
|
|
*******************************************************************************
|
|
|
|
* file name: uset_props.cpp
|
|
|
|
* encoding: UTF-8
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 2004aug30
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*
|
|
|
|
* C wrappers around UnicodeSet functions that are implemented in
|
|
|
|
* uniset_props.cpp, split off for modularization.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/uobject.h"
|
|
|
|
#include "unicode/uset.h"
|
|
|
|
#include "unicode/uniset.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "unicode/ustring.h"
|
|
|
|
#include "unicode/parsepos.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
|
|
|
U_CAPI USet* U_EXPORT2
|
2023-05-23 02:05:01 +02:00
|
|
|
uset_openPattern(const char16_t* pattern, int32_t patternLength,
|
2020-08-11 11:10:23 +02:00
|
|
|
UErrorCode* ec)
|
|
|
|
{
|
|
|
|
UnicodeString pat(patternLength==-1, pattern, patternLength);
|
|
|
|
UnicodeSet* set = new UnicodeSet(pat, *ec);
|
2023-05-23 02:05:01 +02:00
|
|
|
/* test for nullptr */
|
2024-05-14 10:41:19 +02:00
|
|
|
if (set == nullptr) {
|
2020-08-11 11:10:23 +02:00
|
|
|
*ec = U_MEMORY_ALLOCATION_ERROR;
|
2024-05-14 10:41:19 +02:00
|
|
|
return nullptr;
|
2020-08-11 11:10:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (U_FAILURE(*ec)) {
|
|
|
|
delete set;
|
2023-05-23 02:05:01 +02:00
|
|
|
set = nullptr;
|
2020-08-11 11:10:23 +02:00
|
|
|
}
|
|
|
|
return (USet*) set;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI USet* U_EXPORT2
|
2023-05-23 02:05:01 +02:00
|
|
|
uset_openPatternOptions(const char16_t* pattern, int32_t patternLength,
|
2020-08-11 11:10:23 +02:00
|
|
|
uint32_t options,
|
|
|
|
UErrorCode* ec)
|
|
|
|
{
|
|
|
|
UnicodeString pat(patternLength==-1, pattern, patternLength);
|
2023-05-23 02:05:01 +02:00
|
|
|
UnicodeSet* set = new UnicodeSet(pat, options, nullptr, *ec);
|
|
|
|
/* test for nullptr */
|
2024-05-14 10:41:19 +02:00
|
|
|
if (set == nullptr) {
|
2020-08-11 11:10:23 +02:00
|
|
|
*ec = U_MEMORY_ALLOCATION_ERROR;
|
2024-05-14 10:41:19 +02:00
|
|
|
return nullptr;
|
2020-08-11 11:10:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (U_FAILURE(*ec)) {
|
|
|
|
delete set;
|
2023-05-23 02:05:01 +02:00
|
|
|
set = nullptr;
|
2020-08-11 11:10:23 +02:00
|
|
|
}
|
|
|
|
return (USet*) set;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
uset_applyPattern(USet *set,
|
2023-05-23 02:05:01 +02:00
|
|
|
const char16_t *pattern, int32_t patternLength,
|
2020-08-11 11:10:23 +02:00
|
|
|
uint32_t options,
|
|
|
|
UErrorCode *status){
|
|
|
|
|
|
|
|
// status code needs to be checked since we
|
|
|
|
// dereference it
|
2023-05-23 02:05:01 +02:00
|
|
|
if(status == nullptr || U_FAILURE(*status)){
|
2020-08-11 11:10:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check only the set paramenter
|
2023-05-23 02:05:01 +02:00
|
|
|
// if pattern is nullptr or NUL terminated
|
2020-08-11 11:10:23 +02:00
|
|
|
// UnicodeString constructor takes care of it
|
2023-05-23 02:05:01 +02:00
|
|
|
if(set == nullptr){
|
2020-08-11 11:10:23 +02:00
|
|
|
*status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
UnicodeString pat(pattern, patternLength);
|
|
|
|
|
|
|
|
ParsePosition pos;
|
|
|
|
|
2023-05-23 02:05:01 +02:00
|
|
|
((UnicodeSet*) set)->applyPattern(pat, pos, options, nullptr, *status);
|
2020-08-11 11:10:23 +02:00
|
|
|
|
|
|
|
return pos.getIndex();
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
uset_applyIntPropertyValue(USet* set,
|
|
|
|
UProperty prop, int32_t value, UErrorCode* ec) {
|
|
|
|
((UnicodeSet*) set)->applyIntPropertyValue(prop, value, *ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
uset_applyPropertyAlias(USet* set,
|
2023-05-23 02:05:01 +02:00
|
|
|
const char16_t *prop, int32_t propLength,
|
|
|
|
const char16_t *value, int32_t valueLength,
|
2020-08-11 11:10:23 +02:00
|
|
|
UErrorCode* ec) {
|
|
|
|
|
|
|
|
UnicodeString p(prop, propLength);
|
|
|
|
UnicodeString v(value, valueLength);
|
|
|
|
|
|
|
|
((UnicodeSet*) set)->applyPropertyAlias(p, v, *ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI UBool U_EXPORT2
|
2023-05-23 02:05:01 +02:00
|
|
|
uset_resemblesPattern(const char16_t *pattern, int32_t patternLength,
|
2020-08-11 11:10:23 +02:00
|
|
|
int32_t pos) {
|
|
|
|
|
|
|
|
UnicodeString pat(pattern, patternLength);
|
|
|
|
|
|
|
|
return ((pos+1) < pat.length() &&
|
2023-05-23 02:05:01 +02:00
|
|
|
pat.charAt(pos) == (char16_t)91/*[*/) ||
|
2020-08-11 11:10:23 +02:00
|
|
|
UnicodeSet::resemblesPattern(pat, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI int32_t U_EXPORT2
|
|
|
|
uset_toPattern(const USet* set,
|
2023-05-23 02:05:01 +02:00
|
|
|
char16_t* result, int32_t resultCapacity,
|
2020-08-11 11:10:23 +02:00
|
|
|
UBool escapeUnprintable,
|
|
|
|
UErrorCode* ec) {
|
|
|
|
UnicodeString pat;
|
|
|
|
((const UnicodeSet*) set)->toPattern(pat, escapeUnprintable);
|
|
|
|
return pat.extract(result, resultCapacity, *ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
uset_closeOver(USet* set, int32_t attributes) {
|
|
|
|
((UnicodeSet*) set)->UnicodeSet::closeOver(attributes);
|
|
|
|
}
|