~ubuntu-branches/ubuntu/gutsy/icu/gutsy-updates

« back to all changes in this revision

Viewing changes to source/common/charstr.h

  • Committer: Package Import Robot
  • Author(s): Jay Berkenbilt
  • Date: 2005-11-19 11:29:31 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20051119112931-vcizkrp10tli4enw
Tags: 3.4-3
Explicitly build with g++ 3.4.  The current ICU fails its test suite
with 4.0 but not with 3.4.  Future versions should work properly with
4.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
**********************************************************************
3
 
*   Copyright (c) 2001, International Business Machines
4
 
*   Corporation and others.  All Rights Reserved.
5
 
**********************************************************************
6
 
*   Date        Name        Description
7
 
*   11/19/2001  aliu        Creation.
8
 
**********************************************************************
9
 
*/
10
 
 
11
 
#include "unicode/utypes.h"
12
 
#include "unicode/unistr.h"
13
 
 
14
 
//--------------------------------------------------------------------
15
 
// class CharString
16
 
//
17
 
// This is a tiny wrapper class that is used internally to make a
18
 
// UnicodeString look like a const char*.  It can be allocated on the
19
 
// stack.  It only creates a heap buffer if it needs to.
20
 
//--------------------------------------------------------------------
21
 
 
22
 
U_NAMESPACE_BEGIN
23
 
 
24
 
class CharString {
25
 
 public:
26
 
    inline CharString(const UnicodeString& str);
27
 
    inline ~CharString();
28
 
    inline operator const char*() { return ptr; }
29
 
 private:
30
 
    char buf[128];
31
 
    char* ptr;
32
 
};
33
 
 
34
 
inline CharString::CharString(const UnicodeString& str) {
35
 
    // TODO This isn't quite right -- we should probably do
36
 
    // preflighting here to determine the real length.
37
 
    if (str.length() >= (int32_t)sizeof(buf)) {
38
 
        ptr = new char[str.length() + 8];
39
 
    } else {
40
 
        ptr = buf;
41
 
    }
42
 
    str.extract(0, 0x7FFFFFFF, ptr, "");
43
 
}
44
 
 
45
 
inline CharString::~CharString() {
46
 
    if (ptr != buf) {
47
 
        delete[] ptr;
48
 
    }
49
 
}
50
 
 
51
 
U_NAMESPACE_END
52
 
 
53
 
//eof