Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/i18nutil/unicode.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
#pragma once
20
21
#include <com/sun/star/i18n/UnicodeScript.hpp>
22
#include <sal/types.h>
23
#include <rtl/ustrbuf.hxx>
24
#include <unicode/uchar.h>
25
#include <unicode/uscript.h>
26
#include <i18nutil/i18nutildllapi.h>
27
28
class LanguageTag;
29
30
struct ScriptTypeList
31
{
32
    css::i18n::UnicodeScript from;
33
    css::i18n::UnicodeScript to;
34
    sal_Int16 value;
35
};
36
37
class I18NUTIL_DLLPUBLIC unicode
38
{
39
public:
40
    static sal_Int16 getUnicodeType(const sal_uInt32 ch);
41
    static sal_Int16 getUnicodeScriptType(const sal_Unicode ch, const ScriptTypeList* typeList,
42
                                          sal_Int16 unknownType = 0);
43
    static sal_Unicode getUnicodeScriptStart(css::i18n::UnicodeScript type);
44
    static sal_Unicode getUnicodeScriptEnd(css::i18n::UnicodeScript type);
45
    static sal_uInt8 getUnicodeDirection(const sal_Unicode ch);
46
    static sal_uInt32 GetMirroredChar(sal_uInt32);
47
    static bool isControl(const sal_uInt32 ch);
48
    static bool isAlpha(const sal_uInt32 ch);
49
    static bool isSpace(const sal_uInt32 ch);
50
    static bool isWhiteSpace(const sal_uInt32 ch);
51
52
    /** Check for Unicode variation sequence selectors
53
54
        @param nCode  A Unicode code point.
55
56
        @return  True if code is a Unicode variation sequence selector.
57
     */
58
    static bool isVariationSelector(sal_uInt32 nCode)
59
0
    {
60
0
        return u_getIntPropertyValue(nCode, UCHAR_VARIATION_SELECTOR) != 0;
61
0
    }
Unexecuted instantiation: unicode::isVariationSelector(unsigned int)
Unexecuted instantiation: unicode::isVariationSelector(unsigned int)
62
63
    //Map an ISO 15924 script code to Latin/Asian/Complex/Weak
64
    static sal_Int16 getScriptClassFromUScriptCode(UScriptCode eScript);
65
66
    //Return a language that can be written in a given ISO 15924 script code
67
    static OString getExemplarLanguageForUScriptCode(UScriptCode eScript);
68
69
    //Format a number as a percentage according to the rules of the given
70
    //language, e.g. 100 -> "100%" for en-US vs "100 %" for de-DE
71
    static OUString formatPercent(double dNumber, const LanguageTag& rLangTag);
72
73
    /** Map a LanguageTag's language ISO 639 code or script ISO 15924 code or
74
        language-script or locale to Latin/Asian/Complex/Weak. If more than one
75
        script is used with a language(-country) tag then the first (default)
76
        script is mapped for that language.
77
78
        @return a css::i18n::ScriptType value.
79
     */
80
    static sal_Int16 getScriptClassFromLanguageTag(const LanguageTag& rLanguageTag);
81
};
82
83
/*
84
    Toggle between a character and its Unicode Notation.
85
        -implements the concept found in Microsoft Word's Alt-X
86
        -accepts sequences of up to 8 hex characters and converts into the corresponding Unicode Character
87
            -example:  0000A78c   or   2bc
88
        -accepts sequences of up to 256 characters in Unicode notation
89
            -example:  U+00000065u+0331u+308
90
        -handles complex characters (with combining elements) and the all of the Unicode planes.
91
*/
92
class I18NUTIL_DLLPUBLIC ToggleUnicodeCodepoint
93
{
94
private:
95
    OUStringBuffer maInput;
96
    OUStringBuffer maUtf16;
97
    OUStringBuffer maCombining;
98
    bool mbRequiresU = false;
99
    bool mbIsHexString = false;
100
#ifndef NDEBUG
101
    bool mbInputEnded = false;
102
#endif
103
104
public:
105
    /**
106
    Build an input string of valid UTF16/UCS4 units to toggle.
107
        -do not call the other functions until the input process is complete
108
        -build string from Right to Left.  (Start from the character to the left of the cursor: move left.)
109
        - accepted input:
110
          - a sequence of 2 to 8 hex characters not preceded by U+, to convert to Unicode;
111
          - a sequence of up to 256 concatenated U+ notation - like u+xxxxU+yyyy, where xxxx and
112
            yyyy are sequences of 2 to 8 hexadecimal digits - to convert it all to Unicode;
113
          - a single (maybe combined) "symbol" - i.e., one or several codepoints that constitute
114
            one glyph - to convert from Unicode to U+ notation.
115
    */
116
    bool AllowMoreInput(sal_uInt32 uChar);
117
118
    /**
119
    Validates (and potentially modifies) the input string.
120
        -all non-input functions must use this function to first to validate the input string
121
        -additional input may be prevented after this function is called
122
    */
123
    OUString StringToReplace();
124
    OUString ReplacementString();
125
};
126
127
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */