Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/intl/icu/source/common/cstr.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
*   Copyright (C) 2015-2016, International Business Machines
6
*   Corporation and others.  All Rights Reserved.
7
*******************************************************************************
8
*   file name:  charstr.cpp
9
*/
10
#include "unicode/utypes.h"
11
#include "unicode/putil.h"
12
#include "unicode/unistr.h"
13
14
#include "cstr.h"
15
16
#include "charstr.h"
17
#include "uinvchar.h"
18
19
U_NAMESPACE_BEGIN
20
21
0
CStr::CStr(const UnicodeString &in) {
22
0
    UErrorCode status = U_ZERO_ERROR;
23
0
#if !UCONFIG_NO_CONVERSION || U_CHARSET_IS_UTF8
24
0
    int32_t length = in.extract(0, in.length(), static_cast<char *>(NULL), static_cast<uint32_t>(0));
25
0
    int32_t resultCapacity = 0;
26
0
    char *buf = s.getAppendBuffer(length, length, resultCapacity, status);
27
0
    if (U_SUCCESS(status)) {
28
0
        in.extract(0, in.length(), buf, resultCapacity);
29
0
        s.append(buf, length, status);
30
0
    }
31
#else
32
    // No conversion available. Convert any invariant characters; substitute '?' for the rest.
33
    // Note: can't just call u_UCharsToChars() or CharString.appendInvariantChars() on the 
34
    //       whole string because they require that the entire input be invariant.
35
    char buf[2];
36
    for (int i=0; i<in.length(); i = in.moveIndex32(i, 1)) {
37
        if (uprv_isInvariantUString(in.getBuffer()+i, 1)) {
38
            u_UCharsToChars(in.getBuffer()+i, buf, 1);
39
        } else {
40
            buf[0] = '?';
41
        }
42
        s.append(buf, 1, status);
43
    }
44
#endif
45
}
46
47
0
CStr::~CStr() {
48
0
}
49
50
0
const char * CStr::operator ()() const {
51
0
    return s.data();
52
0
}
53
54
U_NAMESPACE_END