]> git.saurik.com Git - apple/icu.git/blame - icuSources/common/resbund_cnv.cpp
ICU-6.2.4.tar.gz
[apple/icu.git] / icuSources / common / resbund_cnv.cpp
CommitLineData
374ca955
A
1/*
2*******************************************************************************
3*
4* Copyright (C) 1997-2004, International Business Machines
5* Corporation and others. All Rights Reserved.
6*
7*******************************************************************************
8* file name: resbund_cnv.cpp
9* encoding: US-ASCII
10* tab size: 8 (not used)
11* indentation:4
12*
13* created on: 2004aug25
14* created by: Markus W. Scherer
15*
16* Character conversion functions moved here from resbund.cpp
17*/
18
19#include "unicode/utypes.h"
20#include "unicode/resbund.h"
21#include "uinvchar.h"
22
23U_NAMESPACE_BEGIN
24
25ResourceBundle::ResourceBundle( const UnicodeString& path,
26 const Locale& locale,
27 UErrorCode& error)
28 :UObject(), fLocale(NULL)
29{
30 constructForLocale(path, locale, error);
31}
32
33ResourceBundle::ResourceBundle( const UnicodeString& path,
34 UErrorCode& error)
35 :UObject(), fLocale(NULL)
36{
37 constructForLocale(path, Locale::getDefault(), error);
38}
39
40void
41ResourceBundle::constructForLocale(const UnicodeString& path,
42 const Locale& locale,
43 UErrorCode& error)
44{
45 char name[300];
46
47 if(path.length() >= (int32_t)sizeof(name)) {
48 fResource = NULL;
49 error = U_ILLEGAL_ARGUMENT_ERROR;
50 } else if(!path.isEmpty()) {
51 if(uprv_isInvariantUString(path.getBuffer(), path.length())) {
52 // the invariant converter is sufficient for package and tree names
53 // and is more efficient
54 path.extract(0, INT32_MAX, name, (int32_t)sizeof(name), US_INV);
55 } else {
56#if !UCONFIG_NO_CONVERSION
57 // use the default converter to support variant-character paths
58 path.extract(name, sizeof(name), 0, error);
59#else
60 // the default converter is not available
61 fResource = NULL;
62 error = U_UNSUPPORTED_ERROR;
63 return;
64#endif
65 }
66 fResource = ures_open(name, locale.getName(), &error);
67 } else {
68 fResource = ures_open(0, locale.getName(), &error);
69 }
70}
71
72U_NAMESPACE_END