1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
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"
38 #include "rtl/string.hxx"
39 #include "rtl/ustring.hxx"
40 #include "sal/types.h"
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') {
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') {
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') {
74 inline sal_Int32
countOccurrences(rtl::OString
const & text
, char c
) {
76 for (sal_Int32 i
= 0;; ++i
) {
77 i
= text
.indexOf(c
, i
);
86 inline sal_Int32
indexOfAnyAsciiL(
87 rtl::OUString
const & text
, char const * chars
, sal_Int32 charsLen
,
90 for (; index
!= text
.getLength(); ++index
) {
91 sal_Unicode c
= text
[index
];
93 && (rtl_str_indexOfChar_WithLength(
94 chars
, charsLen
, static_cast< char >(c
))
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
));
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */