Bump for 3.6-28
[LibreOffice.git] / l10ntools / source / helper.hxx
blobcc33b71ff8ace4bcb2410f3caec221f1dec75c50
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
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/
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.
15 * Major Contributor(s):
16 * [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
17 * (initial developer) ]
19 * All Rights Reserved.
21 * For minor contributions see the git repository.
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.
30 #ifndef INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
31 #define INCLUDED_L10NTOOLS_SOURCE_HELPER_HXX
33 #include "sal/config.h"
35 #include <algorithm>
36 #include <cassert>
38 #include "rtl/string.hxx"
39 #include "rtl/ustring.hxx"
40 #include "sal/types.h"
42 namespace helper {
44 // cf. comphelper::string::isdigitAsciiString:
45 inline bool isAllAsciiDigits(rtl::OString const & text) {
46 for (sal_Int32 i = 0; i != text.getLength(); ++i) {
47 if (text[i] < '0' || text[i] > '9') {
48 return false;
51 return true;
54 // cf. comphelper::string::isupperAsciiString:
55 inline bool isAllAsciiUpperCase(rtl::OString const & text) {
56 for (sal_Int32 i = 0; i != text.getLength(); ++i) {
57 if (text[i] < 'A' || text[i] > 'Z') {
58 return false;
61 return true;
64 // cf. comphelper::string::islowerAsciiString:
65 inline bool isAllAsciiLowerCase(rtl::OString const & text) {
66 for (sal_Int32 i = 0; i != text.getLength(); ++i) {
67 if (text[i] < 'a' || text[i] > 'z') {
68 return false;
71 return true;
74 inline sal_Int32 countOccurrences(rtl::OString const & text, char c) {
75 sal_Int32 n = 0;
76 for (sal_Int32 i = 0;; ++i) {
77 i = text.indexOf(c, i);
78 if (i == -1) {
79 break;
81 ++n;
83 return n;
86 inline sal_Int32 indexOfAnyAsciiL(
87 rtl::OUString const & text, char const * chars, sal_Int32 charsLen,
88 sal_Int32 index = 0)
90 for (; index != text.getLength(); ++index) {
91 sal_Unicode c = text[index];
92 if (c <= 0x7F
93 && (rtl_str_indexOfChar_WithLength(
94 chars, charsLen, static_cast< char >(c))
95 != -1))
97 return index;
100 return -1;
103 template< typename T > inline T abbreviate(
104 T const & text, sal_Int32 start, sal_Int32 length)
106 start = std::max(sal_Int32(0), start);
107 assert(start <= text.getLength());
108 return text.copy(start, std::min(text.getLength() - start, length));
113 #endif
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */