Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : : *
5 : : * The contents of this file are subject to the Mozilla Public License Version
6 : : * 1.1 (the "License"); you may not use this file except in compliance with
7 : : * the License or as specified alternatively below. You may obtain a copy of
8 : : * the License at http://www.mozilla.org/MPL/
9 : : *
10 : : * Software distributed under the License is distributed on an "AS IS" basis,
11 : : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : : * for the specific language governing rights and limitations under the
13 : : * License.
14 : : *
15 : : * Major Contributor(s):
16 : : * [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
17 : : * (initial developer) ]
18 : : *
19 : : * All Rights Reserved.
20 : : *
21 : : * For minor contributions see the git repository.
22 : : *
23 : : * Alternatively, the contents of this file may be used under the terms of
24 : : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : : * instead of those above.
28 : : */
29 : :
30 : : #ifndef INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
31 : : #define INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
32 : :
33 : : #include "sal/config.h"
34 : :
35 : : #include <algorithm>
36 : : #include <cassert>
37 : :
38 : : #include "rtl/string.hxx"
39 : : #include "rtl/ustring.hxx"
40 : : #include "sal/types.h"
41 : :
42 : : namespace helper {
43 : :
44 : : // cf. comphelper::string::isdigitAsciiString:
45 : 0 : inline bool isAllAsciiDigits(rtl::OString const & text) {
46 : 0 : for (sal_Int32 i = 0; i != text.getLength(); ++i) {
47 : 0 : if (text[i] < '0' || text[i] > '9') {
48 : 0 : return false;
49 : : }
50 : : }
51 : 0 : return true;
52 : : }
53 : :
54 : : // cf. comphelper::string::isupperAsciiString:
55 : 0 : inline bool isAllAsciiUpperCase(rtl::OString const & text) {
56 : 0 : for (sal_Int32 i = 0; i != text.getLength(); ++i) {
57 : 0 : if (text[i] < 'A' || text[i] > 'Z') {
58 : 0 : return false;
59 : : }
60 : : }
61 : 0 : return true;
62 : : }
63 : :
64 : : // cf. comphelper::string::islowerAsciiString:
65 : 0 : inline bool isAllAsciiLowerCase(rtl::OString const & text) {
66 : 0 : for (sal_Int32 i = 0; i != text.getLength(); ++i) {
67 : 0 : if (text[i] < 'a' || text[i] > 'z') {
68 : 0 : return false;
69 : : }
70 : : }
71 : 0 : return true;
72 : : }
73 : :
74 : 0 : inline sal_Int32 countOccurrences(rtl::OString const & text, char c) {
75 : 0 : sal_Int32 n = 0;
76 : 0 : for (sal_Int32 i = 0;; ++i) {
77 : 0 : i = text.indexOf(c, i);
78 : 0 : if (i == -1) {
79 : 0 : break;
80 : : }
81 : 0 : ++n;
82 : : }
83 : 0 : return n;
84 : : }
85 : :
86 : 0 : inline sal_Int32 indexOfAnyAsciiL(
87 : : rtl::OUString const & text, char const * chars, sal_Int32 charsLen,
88 : : sal_Int32 index = 0)
89 : : {
90 : 0 : for (; index != text.getLength(); ++index) {
91 : 0 : sal_Unicode c = text[index];
92 : 0 : if (c <= 0x7F
93 : : && (rtl_str_indexOfChar_WithLength(
94 : 0 : chars, charsLen, static_cast< char >(c))
95 : : != -1))
96 : : {
97 : 0 : return index;
98 : : }
99 : : }
100 : 0 : return -1;
101 : : }
102 : :
103 : 0 : template< typename T > inline T abbreviate(
104 : : T const & text, sal_Int32 start, sal_Int32 length)
105 : : {
106 : 0 : start = std::max(sal_Int32(0), start);
107 : : assert(start <= text.getLength());
108 : 0 : return text.copy(start, std::min(text.getLength() - start, length));
109 : : }
110 : :
111 : : }
112 : :
113 : : #endif
114 : :
115 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|