1/*
2*******************************************************************************
3*
4*   Copyright (C) 2003-2007, International Business Machines
5*   Corporation and others.  All Rights Reserved.
6*
7*******************************************************************************
8*   file name:  ucnv_set.c
9*   encoding:   US-ASCII
10*   tab size:   8 (not used)
11*   indentation:4
12*
13*   created on: 2004sep07
14*   created by: Markus W. Scherer
15*
16*   Conversion API functions using USet (ucnv_getUnicodeSet())
17*   moved here from ucnv.c for removing the dependency of other ucnv_
18*   implementation functions on the USet implementation.
19*/
20
21#include "unicode/utypes.h"
22#include "unicode/uset.h"
23#include "unicode/ucnv.h"
24#include "ucnv_bld.h"
25#include "uset_imp.h"
26
27#if !UCONFIG_NO_CONVERSION
28
29U_CAPI void U_EXPORT2
30ucnv_getUnicodeSet(const UConverter *cnv,
31                   USet *setFillIn,
32                   UConverterUnicodeSet whichSet,
33                   UErrorCode *pErrorCode) {
34    /* argument checking */
35    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
36        return;
37    }
38    if(cnv==NULL || setFillIn==NULL || whichSet<UCNV_ROUNDTRIP_SET || UCNV_SET_COUNT<=whichSet) {
39        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
40        return;
41    }
42
43    /* does this converter support this function? */
44    if(cnv->sharedData->impl->getUnicodeSet==NULL) {
45        *pErrorCode=U_UNSUPPORTED_ERROR;
46        return;
47    }
48
49    {
50        USetAdder sa={
51            NULL,
52            uset_add,
53            uset_addRange,
54            uset_addString,
55            uset_remove,
56            uset_removeRange
57        };
58        sa.set=setFillIn;
59
60        /* empty the set */
61        uset_clear(setFillIn);
62
63        /* call the converter to add the code points it supports */
64        cnv->sharedData->impl->getUnicodeSet(cnv, &sa, whichSet, pErrorCode);
65    }
66}
67
68#endif
69