Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/intl/icu/source/common/ures_cnv.cpp
Line
Count
Source (jump to first uncovered line)
1
// © 2016 and later: Unicode, Inc. and others.
2
// License & terms of use: http://www.unicode.org/copyright.html
3
/*
4
*******************************************************************************
5
*
6
*   Copyright (C) 1997-2006, International Business Machines
7
*   Corporation and others.  All Rights Reserved.
8
*
9
*******************************************************************************
10
*   file name:  ures_cnv.c
11
*   encoding:   UTF-8
12
*   tab size:   8 (not used)
13
*   indentation:4
14
*
15
*   created on: 2004aug25
16
*   created by: Markus W. Scherer
17
*
18
*   Character conversion functions moved here from uresbund.c
19
*/
20
21
#include "unicode/utypes.h"
22
#include "unicode/putil.h"
23
#include "unicode/ustring.h"
24
#include "unicode/ucnv.h"
25
#include "unicode/ures.h"
26
#include "uinvchar.h"
27
#include "ustr_cnv.h"
28
29
U_CAPI UResourceBundle * U_EXPORT2
30
ures_openU(const UChar *myPath, 
31
           const char *localeID, 
32
           UErrorCode *status)
33
0
{
34
0
    char pathBuffer[1024];
35
0
    int32_t length;
36
0
    char *path = pathBuffer;
37
0
38
0
    if(status==NULL || U_FAILURE(*status)) {
39
0
        return NULL;
40
0
    }
41
0
    if(myPath==NULL) {
42
0
        path = NULL;
43
0
    }
44
0
    else {
45
0
        length=u_strlen(myPath);
46
0
        if(length>=(int32_t)sizeof(pathBuffer)) {
47
0
            *status=U_ILLEGAL_ARGUMENT_ERROR;
48
0
            return NULL;
49
0
        } else if(uprv_isInvariantUString(myPath, length)) {
50
0
            /*
51
0
             * the invariant converter is sufficient for package and tree names
52
0
             * and is more efficient
53
0
             */
54
0
            u_UCharsToChars(myPath, path, length+1); /* length+1 to include the NUL */
55
0
        } else {
56
0
#if !UCONFIG_NO_CONVERSION
57
0
            /* use the default converter to support variant-character paths */
58
0
            UConverter *cnv=u_getDefaultConverter(status);
59
0
            length=ucnv_fromUChars(cnv, path, (int32_t)sizeof(pathBuffer), myPath, length, status);
60
0
            u_releaseDefaultConverter(cnv);
61
0
            if(U_FAILURE(*status)) {
62
0
                return NULL;
63
0
            }
64
0
            if(length>=(int32_t)sizeof(pathBuffer)) {
65
0
                /* not NUL-terminated - path too long */
66
0
                *status=U_ILLEGAL_ARGUMENT_ERROR;
67
0
                return NULL;
68
0
            }
69
#else
70
            /* the default converter is not available */
71
            *status=U_UNSUPPORTED_ERROR;
72
            return NULL;
73
#endif
74
        }
75
0
    }
76
0
77
0
    return ures_open(path, localeID, status);
78
0
}