2010-10-14 08:30:07 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-19 19:45:04 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 14:18:43 +00:00
|
|
|
|
2013-10-23 19:18:54 +02:00
|
|
|
#ifndef INCLUDED_RTL_USTRING_HXX
|
|
|
|
#define INCLUDED_RTL_USTRING_HXX
|
2000-09-18 14:18:43 +00:00
|
|
|
|
2013-11-09 15:13:51 -06:00
|
|
|
#include <sal/config.h>
|
2011-11-22 09:34:46 +01:00
|
|
|
|
|
|
|
#include <cassert>
|
2013-08-14 11:45:30 +02:00
|
|
|
#include <new>
|
2012-09-18 11:54:05 +02:00
|
|
|
#include <ostream>
|
2012-12-04 11:52:00 +01:00
|
|
|
#include <string.h>
|
2001-05-09 14:25:04 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
#include <rtl/ustring.h>
|
2000-09-18 14:18:43 +00:00
|
|
|
#include <rtl/string.hxx>
|
2012-03-28 21:33:11 +02:00
|
|
|
#include <rtl/stringutils.hxx>
|
2012-09-18 11:54:05 +02:00
|
|
|
#include <rtl/textenc.h>
|
2013-11-09 15:13:51 -06:00
|
|
|
#include <sal/log.hxx>
|
2000-09-18 14:18:43 +00:00
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2012-12-02 22:29:21 +01:00
|
|
|
#include <rtl/stringconcat.hxx>
|
|
|
|
#endif
|
|
|
|
|
2012-03-28 21:33:11 +02:00
|
|
|
// The unittest uses slightly different code to help check that the proper
|
|
|
|
// calls are made. The class is put into a different namespace to make
|
|
|
|
// sure the compiler generates a different (if generating also non-inline)
|
|
|
|
// copy of the function and does not merge them together. The class
|
|
|
|
// is "brought" into the proper rtl namespace by a typedef below.
|
|
|
|
#ifdef RTL_STRING_UNITTEST
|
|
|
|
#define rtl rtlunittest
|
|
|
|
#endif
|
|
|
|
|
2000-09-18 14:18:43 +00:00
|
|
|
namespace rtl
|
|
|
|
{
|
2012-03-28 21:33:11 +02:00
|
|
|
|
|
|
|
#ifdef RTL_STRING_UNITTEST
|
|
|
|
#undef rtl
|
|
|
|
#endif
|
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2014-12-17 15:47:01 +01:00
|
|
|
/// @cond INTERNAL
|
2014-12-17 16:37:41 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
A simple wrapper around string literal. It is usually not necessary to use, can
|
|
|
|
be mostly used to force OUString operator+ working with operands that otherwise would
|
|
|
|
not trigger it.
|
|
|
|
|
|
|
|
This class is not part of public API and is meant to be used only in LibreOffice code.
|
|
|
|
@since LibreOffice 4.0
|
|
|
|
*/
|
|
|
|
struct SAL_WARN_UNUSED OUStringLiteral
|
|
|
|
{
|
|
|
|
template< int N >
|
2015-02-06 18:24:46 +01:00
|
|
|
explicit SAL_CONSTEXPR OUStringLiteral( const char (&str)[ N ] ) : size( N - 1 ), data( str )
|
|
|
|
{ /* only C++14 constexpr: assert( strlen( str ) == N - 1 ); */ }
|
2014-12-17 16:37:41 +01:00
|
|
|
int size;
|
|
|
|
const char* data;
|
|
|
|
};
|
|
|
|
|
2014-12-17 15:47:01 +01:00
|
|
|
/** A simple wrapper around an ASCII character literal, for use in certain
|
|
|
|
OUString functions designed for efficient processing of string literals.
|
|
|
|
|
2015-04-10 11:50:37 +02:00
|
|
|
@since LibreOffice 5.0
|
2014-12-17 15:47:01 +01:00
|
|
|
*/
|
|
|
|
template<char C> struct SAL_WARN_UNUSED OUStringLiteral1 {
|
|
|
|
static_assert(
|
|
|
|
static_cast<unsigned char>(C) < 0x80,
|
|
|
|
"non-ASCII character in OUStringLiteral1");
|
|
|
|
};
|
2014-12-17 16:37:41 +01:00
|
|
|
|
2014-12-17 15:47:01 +01:00
|
|
|
/// @endcond
|
|
|
|
#endif
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/* ======================================================================= */
|
2000-09-18 14:18:43 +00:00
|
|
|
|
|
|
|
/**
|
2012-11-26 14:50:11 -06:00
|
|
|
This String class provides base functionality for C++ like Unicode
|
|
|
|
character array handling. The advantage of this class is that it
|
|
|
|
handles all the memory management for you - and it does it
|
|
|
|
more efficiently. If you assign a string to another string, the
|
2001-05-09 11:56:53 +00:00
|
|
|
data of both strings are shared (without any copy operation or
|
2001-10-30 12:41:07 +00:00
|
|
|
memory allocation) as long as you do not change the string. This class
|
2012-11-26 14:50:11 -06:00
|
|
|
also stores the length of the string, so that many operations are
|
|
|
|
faster than the C-str-functions.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2012-11-26 14:50:11 -06:00
|
|
|
This class provides only readonly string handling. So you could create
|
2001-05-09 11:56:53 +00:00
|
|
|
a string and you could only query the content from this string.
|
2012-11-26 14:50:11 -06:00
|
|
|
It provides also functionality to change the string, but this results
|
|
|
|
in every case in a new string instance (in the most cases with a
|
2001-05-09 11:56:53 +00:00
|
|
|
memory allocation). You don't have functionality to change the
|
2012-11-26 14:50:11 -06:00
|
|
|
content of the string. If you want to change the string content, then
|
|
|
|
you should use the OStringBuffer class, which provides these
|
|
|
|
functionalities and avoids too much memory allocation.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2012-11-26 14:50:11 -06:00
|
|
|
The design of this class is similar to the string classes in Java so
|
|
|
|
less people should have understanding problems when they use this class.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
|
|
|
|
2015-01-26 14:57:05 +01:00
|
|
|
class SAL_WARN_UNUSED SAL_DLLPUBLIC_RTTI OUString
|
2000-09-18 14:18:43 +00:00
|
|
|
{
|
2001-05-09 11:56:53 +00:00
|
|
|
public:
|
2012-01-05 19:40:38 +01:00
|
|
|
/// @cond INTERNAL
|
2001-05-09 11:56:53 +00:00
|
|
|
rtl_uString * pData;
|
2012-01-05 19:40:38 +01:00
|
|
|
/// @endcond
|
2000-09-18 14:18:43 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
New string containing no characters.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString()
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
pData = 0;
|
|
|
|
rtl_uString_new( &pData );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
New string from OUString.
|
|
|
|
|
|
|
|
@param str a OUString.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString( const OUString & str )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
pData = str.pData;
|
|
|
|
rtl_uString_acquire( pData );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
New string from OUString data.
|
|
|
|
|
|
|
|
@param str a OUString data.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString( rtl_uString * str )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
pData = str;
|
|
|
|
rtl_uString_acquire( pData );
|
|
|
|
}
|
2011-09-01 23:44:10 +01:00
|
|
|
|
2002-08-16 14:17:37 +00:00
|
|
|
/** New OUString from OUString data without acquiring it. Takeover of ownership.
|
|
|
|
|
2012-01-05 19:40:38 +01:00
|
|
|
The SAL_NO_ACQUIRE dummy parameter is only there to distinguish this
|
|
|
|
from other constructors.
|
|
|
|
|
2002-08-16 14:17:37 +00:00
|
|
|
@param str
|
|
|
|
OUString data
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
inline OUString( rtl_uString * str, __sal_NoAcquire )
|
2002-08-16 14:17:37 +00:00
|
|
|
{ pData = str; }
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2005-04-13 07:43:08 +00:00
|
|
|
/**
|
|
|
|
New string from a single Unicode character.
|
|
|
|
|
|
|
|
@param value a Unicode character.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
explicit OUString( sal_Unicode value )
|
2005-04-13 07:43:08 +00:00
|
|
|
: pData (0)
|
|
|
|
{
|
|
|
|
rtl_uString_newFromStr_WithLength( &pData, &value, 1 );
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
New string from a Unicode character buffer array.
|
|
|
|
|
|
|
|
@param value a NULL-terminated Unicode character array.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString( const sal_Unicode * value )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
pData = 0;
|
|
|
|
rtl_uString_newFromStr( &pData, value );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-09-14 13:14:24 +02:00
|
|
|
New string from a Unicode character buffer array.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
|
|
|
@param value a Unicode character array.
|
|
|
|
@param length the number of character which should be copied.
|
2012-11-26 14:50:11 -06:00
|
|
|
The character array length must be greater than
|
|
|
|
or equal to this value.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString( const sal_Unicode * value, sal_Int32 length )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
pData = 0;
|
|
|
|
rtl_uString_newFromStr_WithLength( &pData, value, length );
|
|
|
|
}
|
|
|
|
|
2012-02-22 15:35:41 +01:00
|
|
|
/**
|
2012-02-27 18:30:07 +01:00
|
|
|
New string from an 8-Bit string literal that is expected to contain only
|
|
|
|
characters in the ASCII set (i.e. first 128 characters). This constructor
|
|
|
|
allows an efficient and convenient way to create OUString
|
|
|
|
instances from ASCII literals. When creating strings from data that
|
|
|
|
is not pure ASCII, it needs to be converted to OUString by explicitly
|
|
|
|
providing the encoding to use for the conversion.
|
2012-02-22 15:35:41 +01:00
|
|
|
|
2012-04-02 16:52:36 +02:00
|
|
|
If there are any embedded \0's in the string literal, the result is undefined.
|
2012-04-03 07:38:00 +02:00
|
|
|
Use the overload that explicitly accepts length.
|
2012-04-02 16:52:36 +02:00
|
|
|
|
2012-02-27 18:30:07 +01:00
|
|
|
@param literal the 8-bit ASCII string literal
|
2012-02-22 15:35:41 +01:00
|
|
|
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-02-22 15:35:41 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
OUString( T& literal, typename libreoffice_internal::ConstCharArrayDetector< T, libreoffice_internal::Dummy >::Type = libreoffice_internal::Dummy() )
|
2012-03-28 22:21:03 +02:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2012-03-28 22:21:03 +02:00
|
|
|
pData = 0;
|
2014-07-08 02:19:25 +03:00
|
|
|
if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
|
2013-01-19 13:54:40 +01:00
|
|
|
rtl_uString_new( &pData );
|
|
|
|
else
|
2014-07-08 02:19:25 +03:00
|
|
|
rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
|
2012-03-28 22:21:03 +02:00
|
|
|
#ifdef RTL_STRING_UNITTEST
|
|
|
|
rtl_string_unittest_const_literal = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-02-22 15:35:41 +01:00
|
|
|
#ifdef RTL_STRING_UNITTEST
|
|
|
|
/**
|
|
|
|
* Only used by unittests to detect incorrect conversions.
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
OUString( T&, typename libreoffice_internal::ExceptConstCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
|
2012-03-28 22:21:03 +02:00
|
|
|
{
|
|
|
|
pData = 0;
|
2012-04-06 13:45:47 +02:00
|
|
|
rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
|
2012-03-28 22:21:03 +02:00
|
|
|
rtl_string_unittest_invalid_conversion = true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Only used by unittests to detect incorrect conversions.
|
|
|
|
* @internal
|
|
|
|
*/
|
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
OUString( const T&, typename libreoffice_internal::ExceptCharArrayDetector< T >::Type = libreoffice_internal::Dummy() )
|
2012-02-22 15:35:41 +01:00
|
|
|
{
|
|
|
|
pData = 0;
|
2012-04-06 13:45:47 +02:00
|
|
|
rtl_uString_newFromLiteral( &pData, "!!br0ken!!", 10, 0 ); // set to garbage
|
2012-03-28 22:21:03 +02:00
|
|
|
rtl_string_unittest_invalid_conversion = true;
|
2012-02-22 15:35:41 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2014-12-17 16:37:41 +01:00
|
|
|
/// @cond INTERNAL
|
|
|
|
/**
|
|
|
|
New string from an 8-Bit string literal that is expected to contain only
|
|
|
|
characters in the ASCII set (i.e. first 128 characters).
|
|
|
|
|
|
|
|
This constructor is similar to the "direct template" one, but can be
|
|
|
|
useful in cases where the latter does not work, like in
|
|
|
|
|
|
|
|
OUString(flag ? "a" : "bb")
|
|
|
|
|
|
|
|
written as
|
|
|
|
|
|
|
|
OUString(flag ? OUStringLiteral("a") : OUStringLiteral("bb"))
|
|
|
|
|
2015-04-10 11:50:37 +02:00
|
|
|
@since LibreOffice 5.0
|
2014-12-17 16:37:41 +01:00
|
|
|
*/
|
|
|
|
OUString(OUStringLiteral literal): pData(0) {
|
|
|
|
rtl_uString_newFromLiteral(&pData, literal.data, literal.size, 0);
|
|
|
|
}
|
|
|
|
/// @endcond
|
|
|
|
#endif
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
2012-11-26 14:50:11 -06:00
|
|
|
New string from an 8-Bit character buffer array.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2012-11-26 14:50:11 -06:00
|
|
|
@param value An 8-Bit character array.
|
|
|
|
@param length The number of character which should be converted.
|
2001-05-09 11:56:53 +00:00
|
|
|
The 8-Bit character array length must be
|
2012-11-26 14:50:11 -06:00
|
|
|
greater than or equal to this value.
|
|
|
|
@param encoding The text encoding from which the 8-Bit character
|
2001-05-09 11:56:53 +00:00
|
|
|
sequence should be converted.
|
2012-11-26 14:50:11 -06:00
|
|
|
@param convertFlags Flags which control the conversion.
|
2001-05-09 11:56:53 +00:00
|
|
|
see RTL_TEXTTOUNICODE_FLAGS_...
|
2004-03-30 15:28:31 +00:00
|
|
|
|
|
|
|
@exception std::bad_alloc is thrown if an out-of-memory condition occurs
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
|
|
|
OUString( const sal_Char * value, sal_Int32 length,
|
|
|
|
rtl_TextEncoding encoding,
|
2004-03-30 15:28:31 +00:00
|
|
|
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
pData = 0;
|
|
|
|
rtl_string2UString( &pData, value, length, encoding, convertFlags );
|
2011-11-22 09:34:46 +01:00
|
|
|
if (pData == 0) {
|
2004-03-30 15:28:31 +00:00
|
|
|
throw std::bad_alloc();
|
2011-11-22 09:34:46 +01:00
|
|
|
}
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
2007-07-26 08:05:41 +00:00
|
|
|
|
|
|
|
/** Create a new string from an array of Unicode code points.
|
|
|
|
|
|
|
|
@param codePoints
|
|
|
|
an array of at least codePointCount code points, which each must be in
|
|
|
|
the range from 0 to 0x10FFFF, inclusive. May be null if codePointCount
|
|
|
|
is zero.
|
|
|
|
|
|
|
|
@param codePointCount
|
|
|
|
the non-negative number of code points.
|
|
|
|
|
|
|
|
@exception std::bad_alloc
|
|
|
|
is thrown if either an out-of-memory condition occurs or the resulting
|
|
|
|
number of UTF-16 code units would have been larger than SAL_MAX_INT32.
|
|
|
|
|
|
|
|
@since UDK 3.2.7
|
|
|
|
*/
|
|
|
|
inline explicit OUString(
|
|
|
|
sal_uInt32 const * codePoints, sal_Int32 codePointCount):
|
|
|
|
pData(NULL)
|
|
|
|
{
|
|
|
|
rtl_uString_newFromCodePoints(&pData, codePoints, codePointCount);
|
|
|
|
if (pData == NULL) {
|
|
|
|
throw std::bad_alloc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2012-12-04 18:11:12 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
@internal
|
|
|
|
*/
|
2012-12-02 22:29:21 +01:00
|
|
|
template< typename T1, typename T2 >
|
|
|
|
OUString( const OUStringConcat< T1, T2 >& c )
|
|
|
|
{
|
2012-12-04 15:55:14 +01:00
|
|
|
const sal_Int32 l = c.length();
|
2012-12-05 00:55:13 +01:00
|
|
|
pData = rtl_uString_alloc( l );
|
2012-12-04 11:20:22 +01:00
|
|
|
if (l != 0)
|
|
|
|
{
|
2012-12-05 00:55:13 +01:00
|
|
|
sal_Unicode* end = c.addData( pData->buffer );
|
|
|
|
pData->length = end - pData->buffer;
|
|
|
|
*end = '\0';
|
|
|
|
// TODO realloc in case pData->length is noticeably smaller than l?
|
2012-12-04 11:20:22 +01:00
|
|
|
}
|
2012-12-02 22:29:21 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Release the string data.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
~OUString()
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString_release( pData );
|
|
|
|
}
|
|
|
|
|
2003-09-04 09:56:15 +00:00
|
|
|
/** Provides an OUString const & passing a storage pointer of an
|
|
|
|
rtl_uString * handle.
|
|
|
|
It is more convenient to use C++ OUString member functions when dealing
|
|
|
|
with rtl_uString * handles. Using this function avoids unnecessary
|
|
|
|
acquire()/release() calls for a temporary OUString object.
|
|
|
|
|
|
|
|
@param ppHandle
|
|
|
|
pointer to storage
|
|
|
|
@return
|
|
|
|
OUString const & based on given storage
|
|
|
|
*/
|
|
|
|
static inline OUString const & unacquired( rtl_uString * const * ppHandle )
|
|
|
|
{ return * reinterpret_cast< OUString const * >( ppHandle ); }
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Assign a new string.
|
|
|
|
|
|
|
|
@param str a OUString.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString & operator=( const OUString & str )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString_assign( &pData, str.pData );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-02-28 11:39:48 +01:00
|
|
|
/**
|
|
|
|
Assign a new string from an 8-Bit string literal that is expected to contain only
|
|
|
|
characters in the ASCII set (i.e. first 128 characters). This operator
|
|
|
|
allows an efficient and convenient way to assign OUString
|
|
|
|
instances from ASCII literals. When assigning strings from data that
|
|
|
|
is not pure ASCII, it needs to be converted to OUString by explicitly
|
|
|
|
providing the encoding to use for the conversion.
|
|
|
|
|
|
|
|
@param literal the 8-bit ASCII string literal
|
|
|
|
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-02-28 11:39:48 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, OUString& >::Type operator=( T& literal )
|
2012-02-28 11:39:48 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
if( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 == 0 ) // empty string
|
2013-01-19 13:54:40 +01:00
|
|
|
rtl_uString_new( &pData );
|
|
|
|
else
|
2014-07-08 02:19:25 +03:00
|
|
|
rtl_uString_newFromLiteral( &pData, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, 0 );
|
2012-02-28 11:39:48 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2014-12-17 15:47:01 +01:00
|
|
|
/// @cond INTERNAL
|
|
|
|
/** Assign a new string from a single ASCII character literal.
|
|
|
|
|
2015-04-10 11:50:37 +02:00
|
|
|
@since LibreOffice 5.0
|
2014-12-17 15:47:01 +01:00
|
|
|
*/
|
|
|
|
template<char C> OUString & operator =(OUStringLiteral1<C>) {
|
|
|
|
sal_Unicode const c = C;
|
|
|
|
rtl_uString_newFromStr_WithLength(&pData, &c, 1);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
/// @endcond
|
|
|
|
#endif
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Append a string to this string.
|
|
|
|
|
|
|
|
@param str a OUString.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString & operator+=( const OUString & str )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString_newConcat( &pData, pData, str.pData );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2012-12-04 19:58:11 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
@internal
|
|
|
|
*/
|
|
|
|
template< typename T1, typename T2 >
|
|
|
|
OUString& operator+=( const OUStringConcat< T1, T2 >& c )
|
|
|
|
{
|
|
|
|
const int l = c.length();
|
|
|
|
if( l == 0 )
|
|
|
|
return *this;
|
|
|
|
rtl_uString_ensureCapacity( &pData, pData->length + l );
|
|
|
|
sal_Unicode* end = c.addData( pData->buffer + pData->length );
|
|
|
|
*end = '\0';
|
|
|
|
pData->length = end - pData->buffer;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-12 14:24:10 +05:30
|
|
|
/**
|
|
|
|
Clears the string, i.e, makes a zero-character string
|
|
|
|
@since LibreOffice 4.4
|
|
|
|
*/
|
|
|
|
void clear()
|
|
|
|
{
|
|
|
|
rtl_uString_new( &pData );
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns the length of this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The length is equal to the number of Unicode characters in this string.
|
|
|
|
|
|
|
|
@return the length of the sequence of characters represented by this
|
|
|
|
object.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 getLength() const { return pData->length; }
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2011-01-21 13:43:52 +01:00
|
|
|
/**
|
|
|
|
Checks if a string is empty.
|
|
|
|
|
2013-02-06 21:49:35 +01:00
|
|
|
@return true if the string is empty;
|
|
|
|
false, otherwise.
|
2011-01-24 09:23:09 +00:00
|
|
|
|
|
|
|
@since LibreOffice 3.4
|
2011-01-21 13:43:52 +01:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool isEmpty() const
|
2011-01-21 13:43:52 +01:00
|
|
|
{
|
2012-07-23 12:09:12 +02:00
|
|
|
return pData->length == 0;
|
2011-01-21 13:43:52 +01:00
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
2012-11-26 14:50:11 -06:00
|
|
|
Returns a pointer to the Unicode character buffer for this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
It isn't necessarily NULL terminated.
|
|
|
|
|
2012-11-26 14:50:11 -06:00
|
|
|
@return a pointer to the Unicode characters buffer for this object.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
const sal_Unicode * getStr() const { return pData->buffer; }
|
2001-05-09 11:56:53 +00:00
|
|
|
|
|
|
|
/**
|
2011-10-05 09:20:59 +02:00
|
|
|
Access to individual characters.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2011-10-05 09:20:59 +02:00
|
|
|
@param index must be non-negative and less than length.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2011-10-05 09:20:59 +02:00
|
|
|
@return the character at the given index.
|
|
|
|
|
|
|
|
@since LibreOffice 3.5
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2013-03-28 13:06:36 +01:00
|
|
|
sal_Unicode operator [](sal_Int32 index) const {
|
2013-11-06 13:46:42 +01:00
|
|
|
// silence spurious -Werror=strict-overflow warnings from GCC 4.8.2
|
|
|
|
assert(index >= 0 && static_cast<sal_uInt32>(index) < static_cast<sal_uInt32>(getLength()));
|
2013-03-28 13:06:36 +01:00
|
|
|
return getStr()[index];
|
|
|
|
}
|
2001-05-09 11:56:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Compares two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The comparison is based on the numeric value of each character in
|
|
|
|
the strings and return a value indicating their relationship.
|
|
|
|
This function can't be used for language specific sorting.
|
|
|
|
|
|
|
|
@param str the object to be compared.
|
2001-10-30 12:41:07 +00:00
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 compareTo( const OUString & str ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_compare_WithLength( pData->buffer, pData->length,
|
|
|
|
str.pData->buffer, str.pData->length );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-26 14:50:11 -06:00
|
|
|
Compares two strings with a maximum count of characters.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The comparison is based on the numeric value of each character in
|
|
|
|
the strings and return a value indicating their relationship.
|
|
|
|
This function can't be used for language specific sorting.
|
|
|
|
|
|
|
|
@param str the object to be compared.
|
2001-07-27 12:26:37 +00:00
|
|
|
@param maxLength the maximum count of characters to be compared.
|
2001-10-30 12:41:07 +00:00
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
2011-10-21 10:08:02 +01:00
|
|
|
|
|
|
|
@since UDK 3.2.7
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 compareTo( const OUString & str, sal_Int32 maxLength ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_shortenedCompare_WithLength( pData->buffer, pData->length,
|
2001-07-27 12:26:37 +00:00
|
|
|
str.pData->buffer, str.pData->length, maxLength );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-07-27 12:26:37 +00:00
|
|
|
Compares two strings in reverse order.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The comparison is based on the numeric value of each character in
|
|
|
|
the strings and return a value indicating their relationship.
|
|
|
|
This function can't be used for language specific sorting.
|
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
@param str the object to be compared.
|
2001-10-30 12:41:07 +00:00
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 reverseCompareTo( const OUString & str ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
2001-07-27 12:26:37 +00:00
|
|
|
return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
|
|
|
|
str.pData->buffer, str.pData->length );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
2012-12-17 16:27:22 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
|
|
|
@since LibreOffice 4.1
|
|
|
|
*/
|
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type reverseCompareTo( T& literal ) const
|
2012-12-17 16:27:22 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2012-12-17 16:27:22 +01:00
|
|
|
return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
|
2014-07-08 02:19:25 +03:00
|
|
|
literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
|
2012-12-17 16:27:22 +01:00
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Perform a comparison of two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The result is true if and only if second string
|
|
|
|
represents the same sequence of characters as the first string.
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param str the object to be compared.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if the strings are equal;
|
|
|
|
false, otherwise.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool equals( const OUString & str ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
if ( pData->length != str.pData->length )
|
2014-01-23 18:43:53 +01:00
|
|
|
return false;
|
2001-05-09 11:56:53 +00:00
|
|
|
if ( pData == str.pData )
|
2014-01-23 18:43:53 +01:00
|
|
|
return true;
|
2001-07-27 12:26:37 +00:00
|
|
|
return rtl_ustr_reverseCompare_WithLength( pData->buffer, pData->length,
|
|
|
|
str.pData->buffer, str.pData->length ) == 0;
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Perform a ASCII lowercase comparison of two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The result is true if and only if second string
|
|
|
|
represents the same sequence of characters as the first string,
|
|
|
|
ignoring the case.
|
|
|
|
Character values between 65 and 90 (ASCII A-Z) are interpreted as
|
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param str the object to be compared.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if the strings are equal;
|
|
|
|
false, otherwise.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool equalsIgnoreAsciiCase( const OUString & str ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
if ( pData->length != str.pData->length )
|
2014-01-23 18:43:53 +01:00
|
|
|
return false;
|
2001-05-09 11:56:53 +00:00
|
|
|
if ( pData == str.pData )
|
2014-01-23 18:43:53 +01:00
|
|
|
return true;
|
2001-05-09 11:56:53 +00:00
|
|
|
return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
|
|
|
|
str.pData->buffer, str.pData->length ) == 0;
|
|
|
|
}
|
|
|
|
|
2012-11-27 07:00:04 -06:00
|
|
|
/**
|
|
|
|
Perform a ASCII lowercase comparison of two strings.
|
|
|
|
|
2012-11-28 13:32:31 +01:00
|
|
|
Compare the two strings with uppercase ASCII
|
|
|
|
character values between 65 and 90 (ASCII A-Z) interpreted as
|
2012-11-27 07:00:04 -06:00
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param str the object to be compared.
|
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
2012-11-28 13:32:31 +01:00
|
|
|
|
|
|
|
@since LibreOffice 4.0
|
2012-11-27 07:00:04 -06:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 compareToIgnoreAsciiCase( const OUString & str ) const
|
2012-11-27 07:00:04 -06:00
|
|
|
{
|
|
|
|
return rtl_ustr_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length,
|
|
|
|
str.pData->buffer, str.pData->length );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-08 00:43:47 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 00:43:47 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type equalsIgnoreAsciiCase( T& literal ) const
|
2012-03-08 00:43:47 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
if ( pData->length != libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 )
|
2014-01-23 18:43:53 +01:00
|
|
|
return false;
|
2012-03-08 00:43:47 +01:00
|
|
|
|
|
|
|
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, literal ) == 0;
|
|
|
|
}
|
|
|
|
|
2011-10-18 14:50:21 -04:00
|
|
|
/**
|
2003-08-07 13:56:46 +00:00
|
|
|
Match against a substring appearing in this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2003-08-07 13:56:46 +00:00
|
|
|
The result is true if and only if the second string appears as a substring
|
|
|
|
of this string, at the given position.
|
2001-07-27 12:26:37 +00:00
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param str the object (substring) to be compared.
|
|
|
|
@param fromIndex the index to start the comparion from.
|
2012-11-26 14:50:11 -06:00
|
|
|
The index must be greater than or equal to 0
|
2001-07-27 12:26:37 +00:00
|
|
|
and less or equal as the string length.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if str match with the characters in the string
|
2001-07-27 12:26:37 +00:00
|
|
|
at the given position;
|
2014-01-23 18:43:53 +01:00
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool match( const OUString & str, sal_Int32 fromIndex = 0 ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
|
|
|
|
str.pData->buffer, str.pData->length, str.pData->length ) == 0;
|
|
|
|
}
|
|
|
|
|
2012-03-08 00:43:47 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 00:43:47 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type match( T& literal, sal_Int32 fromIndex = 0 ) const
|
2012-03-08 00:43:47 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2012-03-08 00:43:47 +01:00
|
|
|
return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
|
2014-07-08 02:19:25 +03:00
|
|
|
literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
|
2012-03-08 00:43:47 +01:00
|
|
|
}
|
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
/**
|
2003-08-07 13:56:46 +00:00
|
|
|
Match against a substring appearing in this string, ignoring the case of
|
|
|
|
ASCII letters.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2003-08-07 13:56:46 +00:00
|
|
|
The result is true if and only if the second string appears as a substring
|
|
|
|
of this string, at the given position.
|
2001-07-27 12:26:37 +00:00
|
|
|
Character values between 65 and 90 (ASCII A-Z) are interpreted as
|
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param str the object (substring) to be compared.
|
|
|
|
@param fromIndex the index to start the comparion from.
|
2012-11-26 14:50:11 -06:00
|
|
|
The index must be greater than or equal to 0
|
|
|
|
and less than or equal to the string length.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if str match with the characters in the string
|
2001-07-27 12:26:37 +00:00
|
|
|
at the given position;
|
2014-01-23 18:43:53 +01:00
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool matchIgnoreAsciiCase( const OUString & str, sal_Int32 fromIndex = 0 ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
|
|
|
|
str.pData->buffer, str.pData->length,
|
|
|
|
str.pData->length ) == 0;
|
|
|
|
}
|
|
|
|
|
2012-03-08 00:43:47 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 00:43:47 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type matchIgnoreAsciiCase( T& literal, sal_Int32 fromIndex = 0 ) const
|
2012-03-08 00:43:47 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2012-03-08 00:43:47 +01:00
|
|
|
return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
|
2014-07-08 02:19:25 +03:00
|
|
|
literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ) == 0;
|
2012-03-08 00:43:47 +01:00
|
|
|
}
|
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
/**
|
|
|
|
Compares two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
The comparison is based on the numeric value of each character in
|
|
|
|
the strings and return a value indicating their relationship.
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
|
|
|
127. The ASCII string must be NULL-terminated.
|
|
|
|
This function can't be used for language specific sorting.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
2001-10-30 12:41:07 +00:00
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 compareToAscii( const sal_Char* asciiStr ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length, asciiStr );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-11-26 14:50:11 -06:00
|
|
|
Compares two strings with a maximum count of characters.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
The comparison is based on the numeric value of each character in
|
|
|
|
the strings and return a value indicating their relationship.
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
|
|
|
127. The ASCII string must be NULL-terminated.
|
|
|
|
This function can't be used for language specific sorting.
|
|
|
|
|
2013-03-20 13:04:28 +01:00
|
|
|
@deprecated This is a confusing overload with unexpectedly different
|
|
|
|
semantics from the one-parameter form, so it is marked as deprecated.
|
|
|
|
Practically all uses compare the return value against zero and can thus
|
|
|
|
be replaced with uses of startsWith.
|
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
|
|
|
@param maxLength the maximum count of characters to be compared.
|
2001-10-30 12:41:07 +00:00
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2013-03-20 13:04:28 +01:00
|
|
|
SAL_DEPRECATED(
|
|
|
|
"replace s1.compareToAscii(s2, strlen(s2)) == 0 with s1.startsWith(s2)")
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 compareToAscii( const sal_Char * asciiStr, sal_Int32 maxLength ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer, pData->length,
|
|
|
|
asciiStr, maxLength );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-10-30 12:41:07 +00:00
|
|
|
Compares two strings in reverse order.
|
|
|
|
|
|
|
|
This could be useful, if normally both strings start with the same
|
|
|
|
content. The comparison is based on the numeric value of each character
|
|
|
|
in the strings and return a value indicating their relationship.
|
2001-07-27 12:26:37 +00:00
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
2012-11-26 14:50:11 -06:00
|
|
|
all ASCII characters are in the allowed range between 0 and 127.
|
|
|
|
The ASCII string must be NULL-terminated and must be greater than
|
|
|
|
or equal to asciiStrLength.
|
2001-07-27 12:26:37 +00:00
|
|
|
This function can't be used for language specific sorting.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
|
|
|
@param asciiStrLength the length of the ascii string
|
2001-10-30 12:41:07 +00:00
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 reverseCompareToAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_asciil_reverseCompare_WithLength( pData->buffer, pData->length,
|
|
|
|
asciiStr, asciiStrLength );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Perform a comparison of two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
The result is true if and only if second string
|
|
|
|
represents the same sequence of characters as the first string.
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
|
|
|
127. The ASCII string must be NULL-terminated.
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if the strings are equal;
|
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool equalsAscii( const sal_Char* asciiStr ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_ascii_compare_WithLength( pData->buffer, pData->length,
|
|
|
|
asciiStr ) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Perform a comparison of two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
The result is true if and only if second string
|
|
|
|
represents the same sequence of characters as the first string.
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
2012-11-26 14:50:11 -06:00
|
|
|
127. The ASCII string must be NULL-terminated and must be greater than
|
|
|
|
or equal to asciiStrLength.
|
2001-07-27 12:26:37 +00:00
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
|
|
|
@param asciiStrLength the length of the ascii string
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if the strings are equal;
|
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool equalsAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
if ( pData->length != asciiStrLength )
|
2014-01-23 18:43:53 +01:00
|
|
|
return false;
|
2001-07-27 12:26:37 +00:00
|
|
|
|
2005-03-18 17:45:10 +00:00
|
|
|
return rtl_ustr_asciil_reverseEquals_WithLength(
|
|
|
|
pData->buffer, asciiStr, asciiStrLength );
|
2001-07-27 12:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Perform a ASCII lowercase comparison of two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
The result is true if and only if second string
|
|
|
|
represents the same sequence of characters as the first string,
|
|
|
|
ignoring the case.
|
|
|
|
Character values between 65 and 90 (ASCII A-Z) are interpreted as
|
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
|
|
|
127. The ASCII string must be NULL-terminated.
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if the strings are equal;
|
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool equalsIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
|
|
|
|
}
|
|
|
|
|
2011-10-21 10:08:02 +01:00
|
|
|
/**
|
|
|
|
Compares two ASCII strings ignoring case
|
|
|
|
|
|
|
|
The comparison is based on the numeric value of each character in
|
|
|
|
the strings and return a value indicating their relationship.
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
|
|
|
127. The ASCII string must be NULL-terminated.
|
|
|
|
This function can't be used for language specific sorting.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
|
|
|
@return 0 - if both strings are equal
|
|
|
|
< 0 - if this string is less than the string argument
|
|
|
|
> 0 - if this string is greater than the string argument
|
|
|
|
|
|
|
|
@since LibreOffice 3.5
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 compareToIgnoreAsciiCaseAscii( const sal_Char * asciiStr ) const
|
2011-10-18 14:50:21 -04:00
|
|
|
{
|
|
|
|
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr );
|
|
|
|
}
|
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
/**
|
2012-11-26 14:50:11 -06:00
|
|
|
Perform an ASCII lowercase comparison of two strings.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
The result is true if and only if second string
|
|
|
|
represents the same sequence of characters as the first string,
|
|
|
|
ignoring the case.
|
|
|
|
Character values between 65 and 90 (ASCII A-Z) are interpreted as
|
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
2012-11-26 14:50:11 -06:00
|
|
|
all ASCII characters are in the allowed range between 0 and 127.
|
|
|
|
The ASCII string must be NULL-terminated and must be greater than
|
|
|
|
or equal to asciiStrLength.
|
2001-07-27 12:26:37 +00:00
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
|
|
|
@param asciiStrLength the length of the ascii string
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if the strings are equal;
|
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool equalsIgnoreAsciiCaseAsciiL( const sal_Char * asciiStr, sal_Int32 asciiStrLength ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
if ( pData->length != asciiStrLength )
|
2014-01-23 18:43:53 +01:00
|
|
|
return false;
|
2001-07-27 12:26:37 +00:00
|
|
|
|
|
|
|
return rtl_ustr_ascii_compareIgnoreAsciiCase_WithLength( pData->buffer, pData->length, asciiStr ) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2003-08-07 13:56:46 +00:00
|
|
|
Match against a substring appearing in this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2003-08-07 13:56:46 +00:00
|
|
|
The result is true if and only if the second string appears as a substring
|
|
|
|
of this string, at the given position.
|
2001-07-27 12:26:37 +00:00
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
2012-11-26 14:50:11 -06:00
|
|
|
127. The ASCII string must be NULL-terminated and must be greater than or
|
|
|
|
equal to asciiStrLength.
|
2001-07-27 12:26:37 +00:00
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
2012-01-05 19:40:38 +01:00
|
|
|
@param asciiStr the object (substring) to be compared.
|
|
|
|
@param asciiStrLength the length of asciiStr.
|
2001-07-27 12:26:37 +00:00
|
|
|
@param fromIndex the index to start the comparion from.
|
2012-11-26 14:50:11 -06:00
|
|
|
The index must be greater than or equal to 0
|
|
|
|
and less than or equal to the string length.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if str match with the characters in the string
|
2001-07-27 12:26:37 +00:00
|
|
|
at the given position;
|
2014-01-23 18:43:53 +01:00
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool matchAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_ascii_shortenedCompare_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
|
|
|
|
asciiStr, asciiStrLength ) == 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 08:29:16 +01:00
|
|
|
// This overload is left undefined, to detect calls of matchAsciiL that
|
|
|
|
// erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
|
|
|
|
// RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
|
|
|
|
// platforms):
|
|
|
|
#if SAL_TYPES_SIZEOFLONG == 8
|
|
|
|
void matchAsciiL(char const *, sal_Int32, rtl_TextEncoding) const;
|
|
|
|
#endif
|
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
/**
|
2003-08-07 13:56:46 +00:00
|
|
|
Match against a substring appearing in this string, ignoring the case of
|
|
|
|
ASCII letters.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2003-08-07 13:56:46 +00:00
|
|
|
The result is true if and only if the second string appears as a substring
|
|
|
|
of this string, at the given position.
|
2001-07-27 12:26:37 +00:00
|
|
|
Character values between 65 and 90 (ASCII A-Z) are interpreted as
|
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
2012-11-26 14:50:11 -06:00
|
|
|
127. The ASCII string must be NULL-terminated and must be greater than or
|
|
|
|
equal to asciiStrLength.
|
2001-07-27 12:26:37 +00:00
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
|
|
|
@param asciiStr the 8-Bit ASCII character string to be compared.
|
|
|
|
@param asciiStrLength the length of the ascii string
|
|
|
|
@param fromIndex the index to start the comparion from.
|
2012-11-26 14:50:11 -06:00
|
|
|
The index must be greater than or equal to 0
|
|
|
|
and less than or equal to the string length.
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true if str match with the characters in the string
|
2001-07-27 12:26:37 +00:00
|
|
|
at the given position;
|
2014-01-23 18:43:53 +01:00
|
|
|
false, otherwise.
|
2001-07-27 12:26:37 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool matchIgnoreAsciiCaseAsciiL( const sal_Char* asciiStr, sal_Int32 asciiStrLength, sal_Int32 fromIndex = 0 ) const
|
2001-07-27 12:26:37 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_ascii_shortenedCompareIgnoreAsciiCase_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
|
|
|
|
asciiStr, asciiStrLength ) == 0;
|
|
|
|
}
|
|
|
|
|
2012-02-16 08:29:16 +01:00
|
|
|
// This overload is left undefined, to detect calls of
|
|
|
|
// matchIgnoreAsciiCaseAsciiL that erroneously use
|
|
|
|
// RTL_CONSTASCII_USTRINGPARAM instead of RTL_CONSTASCII_STRINGPARAM (but
|
|
|
|
// would lead to ambiguities on 32 bit platforms):
|
|
|
|
#if SAL_TYPES_SIZEOFLONG == 8
|
|
|
|
void matchIgnoreAsciiCaseAsciiL(char const *, sal_Int32, rtl_TextEncoding)
|
|
|
|
const;
|
|
|
|
#endif
|
|
|
|
|
2012-09-06 13:51:21 +02:00
|
|
|
/**
|
|
|
|
Check whether this string starts with a given substring.
|
|
|
|
|
2013-10-15 22:46:05 +02:00
|
|
|
@param str the substring to be compared
|
|
|
|
|
|
|
|
@param rest if non-null, and this function returns true, then assign a
|
2013-11-12 12:29:04 +02:00
|
|
|
copy of the remainder of this string to *rest. Available since
|
|
|
|
LibreOffice 4.2
|
2012-09-06 13:51:21 +02:00
|
|
|
|
|
|
|
@return true if and only if the given str appears as a substring at the
|
|
|
|
start of this string
|
|
|
|
|
2012-11-20 21:27:47 +01:00
|
|
|
@since LibreOffice 4.0
|
2012-09-06 13:51:21 +02:00
|
|
|
*/
|
2013-10-15 22:46:05 +02:00
|
|
|
bool startsWith(OUString const & str, OUString * rest = 0) const {
|
|
|
|
bool b = match(str, 0);
|
|
|
|
if (b && rest != 0) {
|
|
|
|
*rest = copy(str.getLength());
|
|
|
|
}
|
|
|
|
return b;
|
2012-09-06 13:51:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-11-20 21:27:47 +01:00
|
|
|
@since LibreOffice 4.0
|
2012-09-06 13:51:21 +02:00
|
|
|
*/
|
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type startsWith(
|
2013-10-15 22:46:05 +02:00
|
|
|
T & literal, OUString * rest = 0) const
|
2012-09-06 13:51:21 +02:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
|
2012-11-16 14:16:03 +00:00
|
|
|
&& rtl_ustr_asciil_reverseEquals_WithLength( pData->buffer, literal,
|
2014-07-08 02:19:25 +03:00
|
|
|
libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
|
2013-10-15 22:46:05 +02:00
|
|
|
if (b && rest != 0) {
|
2014-07-08 02:19:25 +03:00
|
|
|
*rest = copy(libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
|
2013-10-15 22:46:05 +02:00
|
|
|
}
|
|
|
|
return b;
|
2012-09-06 13:51:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Check whether this string starts with a given string, ignoring the case of
|
|
|
|
ASCII letters.
|
|
|
|
|
|
|
|
Character values between 65 and 90 (ASCII A-Z) are interpreted as
|
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
2013-10-15 22:46:05 +02:00
|
|
|
@param str the substring to be compared
|
|
|
|
|
|
|
|
@param rest if non-null, and this function returns true, then assign a
|
2013-11-12 12:29:04 +02:00
|
|
|
copy of the remainder of this string to *rest. Available since
|
|
|
|
LibreOffice 4.2
|
2013-10-15 22:46:05 +02:00
|
|
|
|
|
|
|
@return true if and only if the given str appears as a substring at the
|
|
|
|
start of this string, ignoring the case of ASCII letters ("A"--"Z" and
|
|
|
|
"a"--"z")
|
|
|
|
|
2012-11-20 21:27:47 +01:00
|
|
|
@since LibreOffice 4.0
|
2012-09-06 13:51:21 +02:00
|
|
|
*/
|
2013-10-15 22:46:05 +02:00
|
|
|
bool startsWithIgnoreAsciiCase(OUString const & str, OUString * rest = 0)
|
|
|
|
const
|
2012-09-06 13:51:21 +02:00
|
|
|
{
|
2013-10-15 22:46:05 +02:00
|
|
|
bool b = matchIgnoreAsciiCase(str, 0);
|
|
|
|
if (b && rest != 0) {
|
|
|
|
*rest = copy(str.getLength());
|
|
|
|
}
|
|
|
|
return b;
|
2012-09-06 13:51:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-11-20 21:27:47 +01:00
|
|
|
@since LibreOffice 4.0
|
2012-09-06 13:51:21 +02:00
|
|
|
*/
|
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
|
2013-10-15 22:46:05 +02:00
|
|
|
startsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const
|
2012-09-06 13:51:21 +02:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2013-10-15 22:46:05 +02:00
|
|
|
bool b = (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
|
2012-09-06 13:51:21 +02:00
|
|
|
pData->buffer,
|
2014-07-08 02:19:25 +03:00
|
|
|
libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, literal,
|
|
|
|
libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)
|
2012-09-06 13:51:21 +02:00
|
|
|
== 0);
|
2013-10-15 22:46:05 +02:00
|
|
|
if (b && rest != 0) {
|
2014-07-08 02:19:25 +03:00
|
|
|
*rest = copy(libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
|
2013-10-15 22:46:05 +02:00
|
|
|
}
|
|
|
|
return b;
|
2012-09-06 13:51:21 +02:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:26:43 +01:00
|
|
|
/**
|
|
|
|
Check whether this string ends with a given substring.
|
|
|
|
|
2013-10-15 22:46:05 +02:00
|
|
|
@param str the substring to be compared
|
|
|
|
|
|
|
|
@param rest if non-null, and this function returns true, then assign a
|
2013-11-12 12:29:04 +02:00
|
|
|
copy of the remainder of this string to *rest. Available since
|
|
|
|
LibreOffice 4.2
|
2012-02-15 15:26:43 +01:00
|
|
|
|
|
|
|
@return true if and only if the given str appears as a substring at the
|
|
|
|
end of this string
|
|
|
|
|
|
|
|
@since LibreOffice 3.6
|
|
|
|
*/
|
2013-10-15 22:46:05 +02:00
|
|
|
bool endsWith(OUString const & str, OUString * rest = 0) const {
|
|
|
|
bool b = str.getLength() <= getLength()
|
2012-02-15 15:26:43 +01:00
|
|
|
&& match(str, getLength() - str.getLength());
|
2013-10-15 22:46:05 +02:00
|
|
|
if (b && rest != 0) {
|
|
|
|
*rest = copy(0, getLength() - str.getLength());
|
|
|
|
}
|
|
|
|
return b;
|
2012-02-15 15:26:43 +01:00
|
|
|
}
|
|
|
|
|
2012-03-08 00:43:47 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 00:43:47 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
|
2013-10-15 22:46:05 +02:00
|
|
|
endsWith(T & literal, OUString * rest = 0) const
|
2012-03-08 00:43:47 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
|
2012-03-08 00:43:47 +01:00
|
|
|
&& rtl_ustr_asciil_reverseEquals_WithLength(
|
2014-07-08 02:19:25 +03:00
|
|
|
pData->buffer + pData->length - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ), literal,
|
|
|
|
libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
|
2013-10-15 22:46:05 +02:00
|
|
|
if (b && rest != 0) {
|
|
|
|
*rest = copy(
|
|
|
|
0,
|
|
|
|
(getLength()
|
2014-07-08 02:19:25 +03:00
|
|
|
- (libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)));
|
2013-10-15 22:46:05 +02:00
|
|
|
}
|
|
|
|
return b;
|
2012-03-08 00:43:47 +01:00
|
|
|
}
|
|
|
|
|
2007-06-27 12:24:20 +00:00
|
|
|
/**
|
|
|
|
Check whether this string ends with a given ASCII string.
|
|
|
|
|
|
|
|
@param asciiStr a sequence of at least asciiStrLength ASCII characters
|
|
|
|
(bytes in the range 0x00--0x7F)
|
2012-01-05 19:40:38 +01:00
|
|
|
@param asciiStrLength the length of asciiStr; must be non-negative
|
2007-06-27 12:24:20 +00:00
|
|
|
@return true if this string ends with asciiStr; otherwise, false is
|
|
|
|
returned
|
|
|
|
|
|
|
|
@since UDK 3.2.7
|
|
|
|
*/
|
|
|
|
inline bool endsWithAsciiL(char const * asciiStr, sal_Int32 asciiStrLength)
|
|
|
|
const
|
|
|
|
{
|
|
|
|
return asciiStrLength <= pData->length
|
|
|
|
&& rtl_ustr_asciil_reverseEquals_WithLength(
|
|
|
|
pData->buffer + pData->length - asciiStrLength, asciiStr,
|
|
|
|
asciiStrLength);
|
|
|
|
}
|
|
|
|
|
2012-03-08 02:26:15 +01:00
|
|
|
/**
|
|
|
|
Check whether this string ends with a given string, ignoring the case of
|
|
|
|
ASCII letters.
|
|
|
|
|
|
|
|
Character values between 65 and 90 (ASCII A-Z) are interpreted as
|
|
|
|
values between 97 and 122 (ASCII a-z).
|
|
|
|
This function can't be used for language specific comparison.
|
|
|
|
|
2013-10-15 22:46:05 +02:00
|
|
|
@param str the substring to be compared
|
|
|
|
|
|
|
|
@param rest if non-null, and this function returns true, then assign a
|
2013-11-12 12:29:04 +02:00
|
|
|
copy of the remainder of this string to *rest. Available since
|
|
|
|
LibreOffice 4.2
|
2013-10-15 22:46:05 +02:00
|
|
|
|
|
|
|
@return true if and only if the given str appears as a substring at the
|
|
|
|
end of this string, ignoring the case of ASCII letters ("A"--"Z" and
|
|
|
|
"a"--"z")
|
|
|
|
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 02:26:15 +01:00
|
|
|
*/
|
2014-03-18 13:42:37 +02:00
|
|
|
bool endsWithIgnoreAsciiCase(OUString const & str, OUString * rest = 0) const
|
2012-03-08 02:26:15 +01:00
|
|
|
{
|
2013-10-15 22:46:05 +02:00
|
|
|
bool b = str.getLength() <= getLength()
|
2012-03-08 02:26:15 +01:00
|
|
|
&& matchIgnoreAsciiCase(str, getLength() - str.getLength());
|
2013-10-15 22:46:05 +02:00
|
|
|
if (b && rest != 0) {
|
|
|
|
*rest = copy(0, getLength() - str.getLength());
|
|
|
|
}
|
|
|
|
return b;
|
2012-03-08 02:26:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 02:26:15 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type
|
2013-10-15 22:46:05 +02:00
|
|
|
endsWithIgnoreAsciiCase(T & literal, OUString * rest = 0) const
|
2012-03-08 02:26:15 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
bool b = libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 <= pData->length
|
2012-03-08 02:26:15 +01:00
|
|
|
&& (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
|
2014-07-08 02:19:25 +03:00
|
|
|
pData->buffer + pData->length - ( libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 ),
|
|
|
|
libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, literal,
|
|
|
|
libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)
|
2012-03-08 02:26:15 +01:00
|
|
|
== 0);
|
2013-10-15 22:46:05 +02:00
|
|
|
if (b && rest != 0) {
|
|
|
|
*rest = copy(
|
|
|
|
0,
|
|
|
|
(getLength()
|
2014-07-08 02:19:25 +03:00
|
|
|
- (libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1)));
|
2013-10-15 22:46:05 +02:00
|
|
|
}
|
|
|
|
return b;
|
2012-03-08 02:26:15 +01:00
|
|
|
}
|
|
|
|
|
2004-04-14 10:48:46 +00:00
|
|
|
/**
|
|
|
|
Check whether this string ends with a given ASCII string, ignoring the
|
|
|
|
case of ASCII letters.
|
|
|
|
|
|
|
|
@param asciiStr a sequence of at least asciiStrLength ASCII characters
|
|
|
|
(bytes in the range 0x00--0x7F)
|
2012-01-05 19:40:38 +01:00
|
|
|
@param asciiStrLength the length of asciiStr; must be non-negative
|
2004-04-14 10:48:46 +00:00
|
|
|
@return true if this string ends with asciiStr, ignoring the case of ASCII
|
|
|
|
letters ("A"--"Z" and "a"--"z"); otherwise, false is returned
|
|
|
|
*/
|
|
|
|
inline bool endsWithIgnoreAsciiCaseAsciiL(
|
|
|
|
char const * asciiStr, sal_Int32 asciiStrLength) const
|
|
|
|
{
|
|
|
|
return asciiStrLength <= pData->length
|
|
|
|
&& (rtl_ustr_ascii_compareIgnoreAsciiCase_WithLengths(
|
|
|
|
pData->buffer + pData->length - asciiStrLength,
|
|
|
|
asciiStrLength, asciiStr, asciiStrLength)
|
|
|
|
== 0);
|
|
|
|
}
|
|
|
|
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator == ( const OUString& rStr1, const OUString& rStr2 )
|
2012-05-02 10:20:26 +01:00
|
|
|
{ return rStr1.equals(rStr2); }
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator == ( const OUString& rStr1, const sal_Unicode * pStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return rStr1.compareTo( pStr2 ) == 0; }
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator == ( const sal_Unicode * pStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return OUString( pStr1 ).compareTo( rStr2 ) == 0; }
|
|
|
|
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator != ( const OUString& rStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return !(operator == ( rStr1, rStr2 )); }
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator != ( const OUString& rStr1, const sal_Unicode * pStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return !(operator == ( rStr1, pStr2 )); }
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator != ( const sal_Unicode * pStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return !(operator == ( pStr1, rStr2 )); }
|
|
|
|
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator < ( const OUString& rStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return rStr1.compareTo( rStr2 ) < 0; }
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator > ( const OUString& rStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return rStr1.compareTo( rStr2 ) > 0; }
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator <= ( const OUString& rStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return rStr1.compareTo( rStr2 ) <= 0; }
|
2014-06-05 08:10:23 +02:00
|
|
|
friend bool operator >= ( const OUString& rStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return rStr1.compareTo( rStr2 ) >= 0; }
|
|
|
|
|
2012-02-28 11:39:48 +01:00
|
|
|
/**
|
|
|
|
* Compare string to an ASCII string literal.
|
|
|
|
*
|
|
|
|
* This operator is equal to calling equalsAsciiL().
|
|
|
|
*
|
2012-03-09 15:21:53 +01:00
|
|
|
* @since LibreOffice 3.6
|
2012-02-28 11:39:48 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( const OUString& string, T& literal )
|
2012-02-28 11:39:48 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
return string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
|
2012-02-28 11:39:48 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Compare string to an ASCII string literal.
|
|
|
|
*
|
|
|
|
* This operator is equal to calling equalsAsciiL().
|
|
|
|
*
|
2012-03-09 15:21:53 +01:00
|
|
|
* @since LibreOffice 3.6
|
2012-02-28 11:39:48 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator==( T& literal, const OUString& string )
|
2012-02-28 11:39:48 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
return string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
|
2012-02-28 11:39:48 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Compare string to an ASCII string literal.
|
|
|
|
*
|
2012-03-08 00:21:30 +01:00
|
|
|
* This operator is equal to calling !equalsAsciiL().
|
2012-02-28 11:39:48 +01:00
|
|
|
*
|
2012-03-09 15:21:53 +01:00
|
|
|
* @since LibreOffice 3.6
|
2012-02-28 11:39:48 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( const OUString& string, T& literal )
|
2012-02-28 11:39:48 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
|
2012-02-28 11:39:48 +01:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Compare string to an ASCII string literal.
|
|
|
|
*
|
2012-03-08 00:21:30 +01:00
|
|
|
* This operator is equal to calling !equalsAsciiL().
|
2012-02-28 11:39:48 +01:00
|
|
|
*
|
2012-03-09 15:21:53 +01:00
|
|
|
* @since LibreOffice 3.6
|
2012-02-28 11:39:48 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
friend inline typename libreoffice_internal::ConstCharArrayDetector< T, bool >::Type operator!=( T& literal, const OUString& string )
|
2012-02-28 11:39:48 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
return !string.equalsAsciiL( literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1 );
|
2012-02-28 11:39:48 +01:00
|
|
|
}
|
|
|
|
|
2015-02-06 18:24:46 +01:00
|
|
|
#if defined LIBO_INTERNAL_ONLY
|
|
|
|
/// @cond INTERNAL
|
|
|
|
|
|
|
|
/* Comparison between OUString and OUStringLiteral.
|
|
|
|
|
2015-04-10 11:50:37 +02:00
|
|
|
@since LibreOffice 5.0
|
2015-02-06 18:24:46 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
friend bool operator ==(OUString const & lhs, OUStringLiteral const & rhs) {
|
|
|
|
return lhs.equalsAsciiL(rhs.data, rhs.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator !=(OUString const & lhs, OUStringLiteral const & rhs) {
|
|
|
|
return !lhs.equalsAsciiL(rhs.data, rhs.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator <(OUString const & lhs, OUStringLiteral const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
lhs.pData->buffer, lhs.pData->length, rhs.data))
|
|
|
|
< 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator <=(OUString const & lhs, OUStringLiteral const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
lhs.pData->buffer, lhs.pData->length, rhs.data))
|
|
|
|
<= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator >(OUString const & lhs, OUStringLiteral const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
lhs.pData->buffer, lhs.pData->length, rhs.data))
|
|
|
|
> 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator >=(OUString const & lhs, OUStringLiteral const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
lhs.pData->buffer, lhs.pData->length, rhs.data))
|
|
|
|
>= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator ==(OUStringLiteral const & lhs, OUString const & rhs) {
|
|
|
|
return rhs.equalsAsciiL(lhs.data, lhs.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator !=(OUStringLiteral const & lhs, OUString const & rhs) {
|
|
|
|
return !rhs.equalsAsciiL(lhs.data, lhs.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator <(OUStringLiteral const & lhs, OUString const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
rhs.pData->buffer, rhs.pData->length, lhs.data))
|
|
|
|
>= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator <=(OUStringLiteral const & lhs, OUString const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
rhs.pData->buffer, rhs.pData->length, lhs.data))
|
|
|
|
> 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator >(OUStringLiteral const & lhs, OUString const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
rhs.pData->buffer, rhs.pData->length, lhs.data))
|
|
|
|
<= 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend bool operator >=(OUStringLiteral const & lhs, OUString const & rhs) {
|
|
|
|
return
|
|
|
|
(rtl_ustr_ascii_compare_WithLength(
|
|
|
|
rhs.pData->buffer, rhs.pData->length, lhs.data))
|
|
|
|
< 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @endcond
|
|
|
|
#endif
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns a hashcode for this string.
|
|
|
|
|
|
|
|
@return a hash code value for this object.
|
2006-04-19 12:47:40 +00:00
|
|
|
|
2015-01-07 13:45:54 +00:00
|
|
|
@see rtl::OUStringHash for convenient use of std::unordered_map
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 hashCode() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_hashCode_WithLength( pData->buffer, pData->length );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index within this string of the first occurrence of the
|
|
|
|
specified character, starting the search at the specified index.
|
|
|
|
|
|
|
|
@param ch character to be located.
|
|
|
|
@param fromIndex the index to start the search from.
|
2012-11-26 14:50:11 -06:00
|
|
|
The index must be greater than or equal to 0
|
|
|
|
and less than or equal to the string length.
|
2001-05-09 11:56:53 +00:00
|
|
|
@return the index of the first occurrence of the character in the
|
|
|
|
character sequence represented by this string that is
|
|
|
|
greater than or equal to fromIndex, or
|
2001-10-30 12:41:07 +00:00
|
|
|
-1 if the character does not occur.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 indexOf( sal_Unicode ch, sal_Int32 fromIndex = 0 ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
sal_Int32 ret = rtl_ustr_indexOfChar_WithLength( pData->buffer+fromIndex, pData->length-fromIndex, ch );
|
|
|
|
return (ret < 0 ? ret : ret+fromIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index within this string of the last occurrence of the
|
|
|
|
specified character, searching backward starting at the end.
|
|
|
|
|
|
|
|
@param ch character to be located.
|
|
|
|
@return the index of the last occurrence of the character in the
|
|
|
|
character sequence represented by this string, or
|
2001-10-30 12:41:07 +00:00
|
|
|
-1 if the character does not occur.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 lastIndexOf( sal_Unicode ch ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, pData->length, ch );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index within this string of the last occurrence of the
|
2007-11-23 12:16:31 +00:00
|
|
|
specified character, searching backward starting before the specified
|
|
|
|
index.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
|
|
|
@param ch character to be located.
|
2007-11-23 12:16:31 +00:00
|
|
|
@param fromIndex the index before which to start the search.
|
2001-05-09 11:56:53 +00:00
|
|
|
@return the index of the last occurrence of the character in the
|
|
|
|
character sequence represented by this string that
|
2007-11-23 12:16:31 +00:00
|
|
|
is less than fromIndex, or -1
|
2001-05-09 11:56:53 +00:00
|
|
|
if the character does not occur before that point.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 lastIndexOf( sal_Unicode ch, sal_Int32 fromIndex ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_lastIndexOfChar_WithLength( pData->buffer, fromIndex, ch );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index within this string of the first occurrence of the
|
|
|
|
specified substring, starting at the specified index.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
|
|
|
If str doesn't include any character, always -1 is
|
2001-05-09 11:56:53 +00:00
|
|
|
returned. This is also the case, if both strings are empty.
|
|
|
|
|
|
|
|
@param str the substring to search for.
|
|
|
|
@param fromIndex the index to start the search from.
|
|
|
|
@return If the string argument occurs one or more times as a substring
|
|
|
|
within this string at the starting index, then the index
|
|
|
|
of the first character of the first such substring is
|
|
|
|
returned. If it does not occur as a substring starting
|
2001-10-30 12:41:07 +00:00
|
|
|
at fromIndex or beyond, -1 is returned.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 indexOf( const OUString & str, sal_Int32 fromIndex = 0 ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
sal_Int32 ret = rtl_ustr_indexOfStr_WithLength( pData->buffer+fromIndex, pData->length-fromIndex,
|
|
|
|
str.pData->buffer, str.pData->length );
|
|
|
|
return (ret < 0 ? ret : ret+fromIndex);
|
|
|
|
}
|
|
|
|
|
2012-03-08 00:43:47 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 00:43:47 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type indexOf( T& literal, sal_Int32 fromIndex = 0 ) const
|
2012-03-08 00:43:47 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2012-03-08 00:43:47 +01:00
|
|
|
sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
|
2012-03-28 22:21:03 +02:00
|
|
|
pData->buffer + fromIndex, pData->length - fromIndex, literal,
|
2014-07-08 02:19:25 +03:00
|
|
|
libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
|
2012-03-08 00:43:47 +01:00
|
|
|
return ret < 0 ? ret : ret + fromIndex;
|
|
|
|
}
|
|
|
|
|
2007-06-27 12:24:20 +00:00
|
|
|
/**
|
|
|
|
Returns the index within this string of the first occurrence of the
|
|
|
|
specified ASCII substring, starting at the specified index.
|
|
|
|
|
|
|
|
@param str
|
|
|
|
the substring to be searched for. Need not be null-terminated, but must
|
|
|
|
be at least as long as the specified len. Must only contain characters
|
|
|
|
in the ASCII range 0x00--7F.
|
|
|
|
|
|
|
|
@param len
|
|
|
|
the length of the substring; must be non-negative.
|
|
|
|
|
|
|
|
@param fromIndex
|
|
|
|
the index to start the search from. Must be in the range from zero to
|
|
|
|
the length of this string, inclusive.
|
|
|
|
|
|
|
|
@return
|
|
|
|
the index (starting at 0) of the first character of the first occurrence
|
|
|
|
of the substring within this string starting at the given fromIndex, or
|
|
|
|
-1 if the substring does not occur. If len is zero, -1 is returned.
|
|
|
|
|
|
|
|
@since UDK 3.2.7
|
|
|
|
*/
|
|
|
|
sal_Int32 indexOfAsciiL(
|
|
|
|
char const * str, sal_Int32 len, sal_Int32 fromIndex = 0) const
|
|
|
|
{
|
|
|
|
sal_Int32 ret = rtl_ustr_indexOfAscii_WithLength(
|
|
|
|
pData->buffer + fromIndex, pData->length - fromIndex, str, len);
|
|
|
|
return ret < 0 ? ret : ret + fromIndex;
|
|
|
|
}
|
|
|
|
|
2012-02-16 08:29:16 +01:00
|
|
|
// This overload is left undefined, to detect calls of indexOfAsciiL that
|
|
|
|
// erroneously use RTL_CONSTASCII_USTRINGPARAM instead of
|
|
|
|
// RTL_CONSTASCII_STRINGPARAM (but would lead to ambiguities on 32 bit
|
|
|
|
// platforms):
|
|
|
|
#if SAL_TYPES_SIZEOFLONG == 8
|
|
|
|
void indexOfAsciiL(char const *, sal_Int32 len, rtl_TextEncoding) const;
|
|
|
|
#endif
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns the index within this string of the last occurrence of
|
|
|
|
the specified substring, searching backward starting at the end.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The returned index indicates the starting index of the substring
|
|
|
|
in this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
If str doesn't include any character, always -1 is
|
2001-05-09 11:56:53 +00:00
|
|
|
returned. This is also the case, if both strings are empty.
|
|
|
|
|
|
|
|
@param str the substring to search for.
|
|
|
|
@return If the string argument occurs one or more times as a substring
|
|
|
|
within this string, then the index of the first character of
|
|
|
|
the last such substring is returned. If it does not occur as
|
2001-10-30 12:41:07 +00:00
|
|
|
a substring, -1 is returned.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 lastIndexOf( const OUString & str ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, pData->length,
|
|
|
|
str.pData->buffer, str.pData->length );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the index within this string of the last occurrence of
|
2007-11-23 12:16:31 +00:00
|
|
|
the specified substring, searching backward starting before the specified
|
|
|
|
index.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
The returned index indicates the starting index of the substring
|
|
|
|
in this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
If str doesn't include any character, always -1 is
|
2001-05-09 11:56:53 +00:00
|
|
|
returned. This is also the case, if both strings are empty.
|
|
|
|
|
|
|
|
@param str the substring to search for.
|
2007-11-23 12:16:31 +00:00
|
|
|
@param fromIndex the index before which to start the search.
|
2001-05-09 11:56:53 +00:00
|
|
|
@return If the string argument occurs one or more times as a substring
|
2007-11-23 12:16:31 +00:00
|
|
|
within this string before the starting index, then the index
|
2001-05-09 11:56:53 +00:00
|
|
|
of the first character of the last such substring is
|
2007-11-23 12:16:31 +00:00
|
|
|
returned. Otherwise, -1 is returned.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 lastIndexOf( const OUString & str, sal_Int32 fromIndex ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_lastIndexOfStr_WithLength( pData->buffer, fromIndex,
|
|
|
|
str.pData->buffer, str.pData->length );
|
|
|
|
}
|
|
|
|
|
2012-03-08 00:43:47 +01:00
|
|
|
/**
|
|
|
|
@overload
|
|
|
|
This function accepts an ASCII string literal as its argument.
|
2012-03-09 15:21:53 +01:00
|
|
|
@since LibreOffice 3.6
|
2012-03-08 00:43:47 +01:00
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
typename libreoffice_internal::ConstCharArrayDetector< T, sal_Int32 >::Type lastIndexOf( T& literal ) const
|
2012-03-08 00:43:47 +01:00
|
|
|
{
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( literal ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2012-03-08 00:43:47 +01:00
|
|
|
return rtl_ustr_lastIndexOfAscii_WithLength(
|
2014-07-08 02:19:25 +03:00
|
|
|
pData->buffer, pData->length, literal, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1);
|
2012-03-08 00:43:47 +01:00
|
|
|
}
|
|
|
|
|
2007-06-27 12:24:20 +00:00
|
|
|
/**
|
|
|
|
Returns the index within this string of the last occurrence of the
|
|
|
|
specified ASCII substring.
|
|
|
|
|
|
|
|
@param str
|
|
|
|
the substring to be searched for. Need not be null-terminated, but must
|
|
|
|
be at least as long as the specified len. Must only contain characters
|
|
|
|
in the ASCII range 0x00--7F.
|
|
|
|
|
|
|
|
@param len
|
|
|
|
the length of the substring; must be non-negative.
|
|
|
|
|
|
|
|
@return
|
|
|
|
the index (starting at 0) of the first character of the last occurrence
|
|
|
|
of the substring within this string, or -1 if the substring does not
|
|
|
|
occur. If len is zero, -1 is returned.
|
|
|
|
|
|
|
|
@since UDK 3.2.7
|
|
|
|
*/
|
|
|
|
sal_Int32 lastIndexOfAsciiL(char const * str, sal_Int32 len) const
|
|
|
|
{
|
|
|
|
return rtl_ustr_lastIndexOfAscii_WithLength(
|
|
|
|
pData->buffer, pData->length, str, len);
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
2001-10-30 12:41:07 +00:00
|
|
|
Returns a new string that is a substring of this string.
|
|
|
|
|
2012-10-02 18:39:30 +01:00
|
|
|
The substring begins at the specified beginIndex. If
|
|
|
|
beginIndex is negative or be greater than the length of
|
|
|
|
this string, behaviour is undefined.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
|
|
|
@param beginIndex the beginning index, inclusive.
|
|
|
|
@return the specified substring.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
2012-10-02 18:39:30 +01:00
|
|
|
rtl_uString *pNew = 0;
|
|
|
|
rtl_uString_newFromSubString( &pNew, pData, beginIndex, getLength() - beginIndex );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2001-10-30 12:41:07 +00:00
|
|
|
Returns a new string that is a substring of this string.
|
|
|
|
|
2002-10-16 11:08:09 +00:00
|
|
|
The substring begins at the specified beginIndex and contains count
|
2012-10-02 18:39:30 +01:00
|
|
|
characters. If either beginIndex or count are negative,
|
|
|
|
or beginIndex + count are greater than the length of this string
|
|
|
|
then behaviour is undefined.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
|
|
|
@param beginIndex the beginning index, inclusive.
|
|
|
|
@param count the number of characters.
|
|
|
|
@return the specified substring.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString copy( sal_Int32 beginIndex, sal_Int32 count ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
2012-10-02 18:39:30 +01:00
|
|
|
rtl_uString *pNew = 0;
|
|
|
|
rtl_uString_newFromSubString( &pNew, pData, beginIndex, count );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Concatenates the specified string to the end of this string.
|
|
|
|
|
|
|
|
@param str the string that is concatenated to the end
|
|
|
|
of this string.
|
|
|
|
@return a string that represents the concatenation of this string
|
|
|
|
followed by the string argument.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString concat( const OUString & str ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString* pNew = 0;
|
|
|
|
rtl_uString_newConcat( &pNew, pData, str.pData );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#ifndef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2014-06-05 08:10:23 +02:00
|
|
|
friend OUString operator+( const OUString& rStr1, const OUString& rStr2 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rStr1.concat( rStr2 );
|
|
|
|
}
|
2012-12-02 22:29:21 +01:00
|
|
|
#endif
|
2001-05-09 11:56:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing n = count characters
|
|
|
|
from position index in this string with newStr.
|
|
|
|
|
|
|
|
@param index the replacing index in str.
|
2012-11-26 14:50:11 -06:00
|
|
|
The index must be greater than or equal to 0 and
|
|
|
|
less than or equal to the length of the string.
|
2013-02-24 21:33:12 +01:00
|
|
|
@param count the count of characters that will be replaced
|
2012-11-26 14:50:11 -06:00
|
|
|
The count must be greater than or equal to 0 and
|
|
|
|
less than or equal to the length of the string minus index.
|
2001-05-09 11:56:53 +00:00
|
|
|
@param newStr the new substring.
|
|
|
|
@return the new string.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString replaceAt( sal_Int32 index, sal_Int32 count, const OUString& newStr ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString* pNew = 0;
|
|
|
|
rtl_uString_newReplaceStrAt( &pNew, pData, index, count, newStr.pData );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing all occurrences of
|
|
|
|
oldChar in this string with newChar.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
If the character oldChar does not occur in the character sequence
|
|
|
|
represented by this object, then the string is assigned with
|
|
|
|
str.
|
|
|
|
|
|
|
|
@param oldChar the old character.
|
|
|
|
@param newChar the new character.
|
|
|
|
@return a string derived from this string by replacing every
|
|
|
|
occurrence of oldChar with newChar.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString replace( sal_Unicode oldChar, sal_Unicode newChar ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString* pNew = 0;
|
|
|
|
rtl_uString_newReplace( &pNew, pData, oldChar, newChar );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:26:43 +01:00
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing the first occurrence of a
|
|
|
|
given substring with another substring.
|
|
|
|
|
|
|
|
@param from the substring to be replaced
|
|
|
|
|
|
|
|
@param to the replacing substring
|
|
|
|
|
|
|
|
@param[in,out] index pointer to a start index; if the pointer is
|
2012-11-26 14:50:11 -06:00
|
|
|
non-null: upon entry to the function, its value is the index into this
|
2012-02-15 15:26:43 +01:00
|
|
|
string at which to start searching for the \p from substring, the value
|
2012-11-26 14:50:11 -06:00
|
|
|
must be non-negative and not greater than this string's length; upon exiting
|
|
|
|
the function its value is the index into this string at which the
|
2012-02-15 15:26:43 +01:00
|
|
|
replacement took place or -1 if no replacement took place; if the pointer
|
|
|
|
is null, searching always starts at index 0
|
|
|
|
|
|
|
|
@since LibreOffice 3.6
|
|
|
|
*/
|
2012-11-28 04:01:17 -06:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString replaceFirst(
|
2012-02-15 15:26:43 +01:00
|
|
|
OUString const & from, OUString const & to, sal_Int32 * index = 0) const
|
|
|
|
{
|
|
|
|
rtl_uString * s = 0;
|
|
|
|
sal_Int32 i = 0;
|
|
|
|
rtl_uString_newReplaceFirst(
|
|
|
|
&s, pData, from.pData, to.pData, index == 0 ? &i : index);
|
|
|
|
return OUString(s, SAL_NO_ACQUIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing the first occurrence of a
|
|
|
|
given substring with another substring.
|
|
|
|
|
2012-03-08 00:45:43 +01:00
|
|
|
@param from ASCII string literal, the substring to be replaced
|
2012-02-15 15:26:43 +01:00
|
|
|
|
|
|
|
@param to the replacing substring
|
|
|
|
|
|
|
|
@param[in,out] index pointer to a start index; if the pointer is
|
|
|
|
non-null: upon entry to the function, its value is the index into the this
|
|
|
|
string at which to start searching for the \p from substring, the value
|
2012-11-26 14:50:11 -06:00
|
|
|
must be non-negative and not greater than this string's length; upon exiting
|
|
|
|
the function its value is the index into this string at which the
|
2012-02-15 15:26:43 +01:00
|
|
|
replacement took place or -1 if no replacement took place; if the pointer
|
|
|
|
is null, searching always starts at index 0
|
|
|
|
|
|
|
|
@since LibreOffice 3.6
|
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceFirst( T& from, OUString const & to,
|
2012-11-28 04:01:17 -06:00
|
|
|
sal_Int32 * index = 0) const
|
2012-02-15 15:26:43 +01:00
|
|
|
{
|
|
|
|
rtl_uString * s = 0;
|
|
|
|
sal_Int32 i = 0;
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
2012-02-15 15:26:43 +01:00
|
|
|
rtl_uString_newReplaceFirstAsciiL(
|
2014-07-08 02:19:25 +03:00
|
|
|
&s, pData, from, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, to.pData, index == 0 ? &i : index);
|
2012-02-15 15:26:43 +01:00
|
|
|
return OUString(s, SAL_NO_ACQUIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing the first occurrence of a
|
|
|
|
given substring with another substring.
|
|
|
|
|
2012-03-08 00:45:43 +01:00
|
|
|
@param from ASCII string literal, the substring to be replaced
|
2012-02-15 15:26:43 +01:00
|
|
|
|
2012-03-08 00:45:43 +01:00
|
|
|
@param to ASCII string literal, the substring to be replaced
|
2012-02-15 15:26:43 +01:00
|
|
|
|
|
|
|
@param[in,out] index pointer to a start index; if the pointer is
|
|
|
|
non-null: upon entry to the function, its value is the index into the this
|
|
|
|
string at which to start searching for the \p from substring, the value
|
2012-11-26 14:50:11 -06:00
|
|
|
must be non-negative and not greater than this string's length; upon exiting
|
|
|
|
the function its value is the index into this string at which the
|
2012-02-15 15:26:43 +01:00
|
|
|
replacement took place or -1 if no replacement took place; if the pointer
|
|
|
|
is null, searching always starts at index 0
|
|
|
|
|
|
|
|
@since LibreOffice 3.6
|
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T1, typename T2 >
|
2014-07-08 02:19:25 +03:00
|
|
|
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
|
2012-03-28 22:21:03 +02:00
|
|
|
replaceFirst( T1& from, T2& to, sal_Int32 * index = 0) const
|
2012-02-15 15:26:43 +01:00
|
|
|
{
|
|
|
|
rtl_uString * s = 0;
|
|
|
|
sal_Int32 i = 0;
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T1 >::size - 1 );
|
|
|
|
assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T2 >::size - 1 );
|
2012-02-15 15:26:43 +01:00
|
|
|
rtl_uString_newReplaceFirstAsciiLAsciiL(
|
2014-07-08 02:19:25 +03:00
|
|
|
&s, pData, from, libreoffice_internal::ConstCharArrayDetector< T1, void >::size - 1, to,
|
|
|
|
libreoffice_internal::ConstCharArrayDetector< T2, void >::size - 1, index == 0 ? &i : index);
|
2012-02-15 15:26:43 +01:00
|
|
|
return OUString(s, SAL_NO_ACQUIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing all occurrences of a given
|
|
|
|
substring with another substring.
|
|
|
|
|
|
|
|
Replacing subsequent occurrences picks up only after a given replacement.
|
|
|
|
That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
|
|
|
|
|
|
|
|
@param from the substring to be replaced
|
|
|
|
|
|
|
|
@param to the replacing substring
|
|
|
|
|
2012-10-04 15:06:27 +02:00
|
|
|
@param fromIndex the position in the string where we will begin searching
|
|
|
|
|
2012-11-20 21:27:47 +01:00
|
|
|
@since LibreOffice 4.0
|
2012-02-15 15:26:43 +01:00
|
|
|
*/
|
2012-12-11 17:07:26 +04:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString replaceAll(
|
|
|
|
OUString const & from, OUString const & to, sal_Int32 fromIndex = 0) const
|
|
|
|
{
|
2012-02-15 15:26:43 +01:00
|
|
|
rtl_uString * s = 0;
|
2012-10-04 15:06:27 +02:00
|
|
|
rtl_uString_newReplaceAllFromIndex(&s, pData, from.pData, to.pData, fromIndex);
|
2012-02-15 15:26:43 +01:00
|
|
|
return OUString(s, SAL_NO_ACQUIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing all occurrences of a given
|
|
|
|
substring with another substring.
|
|
|
|
|
|
|
|
Replacing subsequent occurrences picks up only after a given replacement.
|
|
|
|
That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
|
|
|
|
|
2012-03-08 00:45:43 +01:00
|
|
|
@param from ASCII string literal, the substring to be replaced
|
2012-02-15 15:26:43 +01:00
|
|
|
|
|
|
|
@param to the replacing substring
|
|
|
|
|
|
|
|
@since LibreOffice 3.6
|
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T >
|
2014-07-08 02:19:25 +03:00
|
|
|
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T, OUString >::Type replaceAll( T& from, OUString const & to) const
|
2012-02-15 15:26:43 +01:00
|
|
|
{
|
|
|
|
rtl_uString * s = 0;
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T >::size - 1 );
|
|
|
|
rtl_uString_newReplaceAllAsciiL(&s, pData, from, libreoffice_internal::ConstCharArrayDetector< T, void >::size - 1, to.pData);
|
2012-02-15 15:26:43 +01:00
|
|
|
return OUString(s, SAL_NO_ACQUIRE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from replacing all occurrences of a given
|
|
|
|
substring with another substring.
|
|
|
|
|
|
|
|
Replacing subsequent occurrences picks up only after a given replacement.
|
|
|
|
That is, replacing from "xa" to "xx" in "xaa" results in "xxa", not "xxx".
|
|
|
|
|
2012-03-08 00:45:43 +01:00
|
|
|
@param from ASCII string literal, the substring to be replaced
|
2012-02-15 15:26:43 +01:00
|
|
|
|
2012-03-08 00:45:43 +01:00
|
|
|
@param to ASCII string literal, the substring to be replaced
|
2012-02-15 15:26:43 +01:00
|
|
|
|
|
|
|
@since LibreOffice 3.6
|
|
|
|
*/
|
2012-03-28 22:21:03 +02:00
|
|
|
template< typename T1, typename T2 >
|
2014-07-08 02:19:25 +03:00
|
|
|
SAL_WARN_UNUSED_RESULT typename libreoffice_internal::ConstCharArrayDetector< T1, typename libreoffice_internal::ConstCharArrayDetector< T2, OUString >::Type >::Type
|
2012-03-28 22:21:03 +02:00
|
|
|
replaceAll( T1& from, T2& to ) const
|
2012-02-15 15:26:43 +01:00
|
|
|
{
|
|
|
|
rtl_uString * s = 0;
|
2014-07-08 02:19:25 +03:00
|
|
|
assert( strlen( from ) == libreoffice_internal::ConstCharArrayDetector< T1 >::size - 1 );
|
|
|
|
assert( strlen( to ) == libreoffice_internal::ConstCharArrayDetector< T2 >::size - 1 );
|
2012-02-15 15:26:43 +01:00
|
|
|
rtl_uString_newReplaceAllAsciiLAsciiL(
|
2014-07-08 02:19:25 +03:00
|
|
|
&s, pData, from, libreoffice_internal::ConstCharArrayDetector< T1, void >::size - 1,
|
|
|
|
to, libreoffice_internal::ConstCharArrayDetector< T2, void >::size - 1);
|
2012-02-15 15:26:43 +01:00
|
|
|
return OUString(s, SAL_NO_ACQUIRE);
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Converts from this string all ASCII uppercase characters (65-90)
|
|
|
|
to ASCII lowercase characters (97-122).
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
If the string doesn't contain characters which must be converted,
|
|
|
|
then the new string is assigned with str.
|
|
|
|
|
|
|
|
@return the string, converted to ASCII lowercase.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString toAsciiLowerCase() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString* pNew = 0;
|
|
|
|
rtl_uString_newToAsciiLowerCase( &pNew, pData );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Converts from this string all ASCII lowercase characters (97-122)
|
|
|
|
to ASCII uppercase characters (65-90).
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
If the string doesn't contain characters which must be converted,
|
|
|
|
then the new string is assigned with str.
|
|
|
|
|
|
|
|
@return the string, converted to ASCII uppercase.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString toAsciiUpperCase() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString* pNew = 0;
|
|
|
|
rtl_uString_newToAsciiUpperCase( &pNew, pData );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a new string resulting from removing white space from both ends
|
2001-10-30 12:41:07 +00:00
|
|
|
of the string.
|
|
|
|
|
|
|
|
All characters that have codes less than or equal to
|
2001-05-09 11:56:53 +00:00
|
|
|
32 (the space character) are considered to be white space.
|
|
|
|
If the string doesn't contain white spaces at both ends,
|
|
|
|
then the new string is assigned with str.
|
|
|
|
|
|
|
|
@return the string, with white space removed from the front and end.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_WARN_UNUSED_RESULT OUString trim() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString* pNew = 0;
|
|
|
|
rtl_uString_newTrim( &pNew, pData );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a token in the string.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
sal_Int32 nIndex = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
...
|
|
|
|
OUString aToken = aStr.getToken( 0, ';', nIndex );
|
|
|
|
...
|
|
|
|
}
|
|
|
|
while ( nIndex >= 0 );
|
|
|
|
|
2004-09-20 07:42:56 +00:00
|
|
|
@param token the number of the token to return
|
2013-05-15 10:42:04 +03:00
|
|
|
@param cTok the character which separate the tokens.
|
2001-05-09 11:56:53 +00:00
|
|
|
@param index the position at which the token is searched in the
|
|
|
|
string.
|
2004-09-20 07:42:56 +00:00
|
|
|
The index must not be greater than the length of the
|
|
|
|
string.
|
2001-05-09 11:56:53 +00:00
|
|
|
This param is set to the position of the
|
|
|
|
next token or to -1, if it is the last token.
|
2004-09-20 07:42:56 +00:00
|
|
|
@return the token; if either token or index is negative, an empty token
|
|
|
|
is returned (and index is set to -1)
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString * pNew = 0;
|
|
|
|
index = rtl_uString_getToken( &pNew, pData, token, cTok, index );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
2012-02-15 15:26:43 +01:00
|
|
|
/**
|
|
|
|
Returns a token from the string.
|
|
|
|
|
|
|
|
The same as getToken(sal_Int32, sal_Unicode, sal_Int32 &), but always
|
|
|
|
passing in 0 as the start index in the third argument.
|
|
|
|
|
|
|
|
@param count the number of the token to return, starting with 0
|
|
|
|
@param separator the character which separates the tokens
|
|
|
|
|
|
|
|
@return the given token, or an empty string
|
|
|
|
|
|
|
|
@since LibreOffice 3.6
|
|
|
|
*/
|
|
|
|
OUString getToken(sal_Int32 count, sal_Unicode separator) const {
|
|
|
|
sal_Int32 n = 0;
|
|
|
|
return getToken(count, separator, n);
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns the Boolean value from this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
2014-01-23 18:43:53 +01:00
|
|
|
@return true, if the string is 1 or "True" in any ASCII case.
|
|
|
|
false in any other case.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
bool toBoolean() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_toBoolean( pData->buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the first character from this string.
|
|
|
|
|
|
|
|
@return the first character from this string or 0, if this string
|
|
|
|
is emptry.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Unicode toChar() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return pData->buffer[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the int32 value from this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@param radix the radix (between 2 and 36)
|
|
|
|
@return the int32 represented from this string.
|
2013-03-25 16:24:48 +01:00
|
|
|
0 if this string represents no number or one of too large
|
|
|
|
magnitude.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int32 toInt32( sal_Int16 radix = 10 ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_toInt32( pData->buffer, radix );
|
|
|
|
}
|
|
|
|
|
2013-06-12 15:58:17 +02:00
|
|
|
/**
|
|
|
|
Returns the uint32 value from this string.
|
|
|
|
|
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@param radix the radix (between 2 and 36)
|
|
|
|
@return the uint32 represented from this string.
|
|
|
|
0 if this string represents no number or one of too large
|
|
|
|
magnitude.
|
|
|
|
|
|
|
|
@since LibreOffice 4.2
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_uInt32 toUInt32( sal_Int16 radix = 10 ) const
|
2013-06-12 15:58:17 +02:00
|
|
|
{
|
|
|
|
return rtl_ustr_toUInt32( pData->buffer, radix );
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns the int64 value from this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@param radix the radix (between 2 and 36)
|
|
|
|
@return the int64 represented from this string.
|
2013-03-25 16:24:48 +01:00
|
|
|
0 if this string represents no number or one of too large
|
|
|
|
magnitude.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_Int64 toInt64( sal_Int16 radix = 10 ) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_toInt64( pData->buffer, radix );
|
|
|
|
}
|
|
|
|
|
2013-02-04 11:14:53 +01:00
|
|
|
/**
|
|
|
|
Returns the uint64 value from this string.
|
|
|
|
|
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@param radix the radix (between 2 and 36)
|
|
|
|
@return the uint64 represented from this string.
|
2013-03-25 16:24:48 +01:00
|
|
|
0 if this string represents no number or one of too large
|
|
|
|
magnitude.
|
2013-03-25 16:20:31 +01:00
|
|
|
|
|
|
|
@since LibreOffice 4.1
|
2013-02-04 11:14:53 +01:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
sal_uInt64 toUInt64( sal_Int16 radix = 10 ) const
|
2013-02-04 11:14:53 +01:00
|
|
|
{
|
|
|
|
return rtl_ustr_toUInt64( pData->buffer, radix );
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns the float value from this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@return the float represented from this string.
|
|
|
|
0.0 if this string represents no number.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
float toFloat() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_toFloat( pData->buffer );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the double value from this string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@return the double represented from this string.
|
|
|
|
0.0 if this string represents no number.
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
double toDouble() const
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
return rtl_ustr_toDouble( pData->buffer );
|
|
|
|
}
|
|
|
|
|
2007-04-03 13:04:29 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Return a canonical representation for a string.
|
|
|
|
|
|
|
|
A pool of strings, initially empty is maintained privately
|
|
|
|
by the string class. On invocation, if present in the pool
|
|
|
|
the original string will be returned. Otherwise this string,
|
|
|
|
or a copy thereof will be added to the pool and returned.
|
|
|
|
|
|
|
|
@return
|
|
|
|
a version of the string from the pool.
|
|
|
|
|
|
|
|
@exception std::bad_alloc is thrown if an out-of-memory condition occurs
|
|
|
|
|
|
|
|
@since UDK 3.2.7
|
|
|
|
*/
|
|
|
|
OUString intern() const
|
|
|
|
{
|
|
|
|
rtl_uString * pNew = 0;
|
|
|
|
rtl_uString_intern( &pNew, pData );
|
2011-11-22 09:34:46 +01:00
|
|
|
if (pNew == 0) {
|
2007-04-03 13:04:29 +00:00
|
|
|
throw std::bad_alloc();
|
2011-11-22 09:34:46 +01:00
|
|
|
}
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2007-04-03 13:04:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return a canonical representation for a converted string.
|
|
|
|
|
|
|
|
A pool of strings, initially empty is maintained privately
|
|
|
|
by the string class. On invocation, if present in the pool
|
|
|
|
the original string will be returned. Otherwise this string,
|
|
|
|
or a copy thereof will be added to the pool and returned.
|
|
|
|
|
|
|
|
@param value a 8-Bit character array.
|
|
|
|
@param length the number of character which should be converted.
|
|
|
|
The 8-Bit character array length must be
|
2012-11-26 14:50:11 -06:00
|
|
|
greater than or equal to this value.
|
2007-04-03 13:04:29 +00:00
|
|
|
@param encoding the text encoding from which the 8-Bit character
|
|
|
|
sequence should be converted.
|
|
|
|
@param convertFlags flags which controls the conversion.
|
|
|
|
see RTL_TEXTTOUNICODE_FLAGS_...
|
|
|
|
@param pInfo pointer to return conversion status or NULL.
|
|
|
|
|
|
|
|
@return
|
|
|
|
a version of the converted string from the pool.
|
|
|
|
|
|
|
|
@exception std::bad_alloc is thrown if an out-of-memory condition occurs
|
|
|
|
|
|
|
|
@since UDK 3.2.7
|
|
|
|
*/
|
|
|
|
static OUString intern( const sal_Char * value, sal_Int32 length,
|
|
|
|
rtl_TextEncoding encoding,
|
|
|
|
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS,
|
|
|
|
sal_uInt32 *pInfo = NULL )
|
|
|
|
{
|
|
|
|
rtl_uString * pNew = 0;
|
|
|
|
rtl_uString_internConvert( &pNew, value, length, encoding,
|
|
|
|
convertFlags, pInfo );
|
2011-11-22 09:34:46 +01:00
|
|
|
if (pNew == 0) {
|
2007-04-03 13:04:29 +00:00
|
|
|
throw std::bad_alloc();
|
2011-11-22 09:34:46 +01:00
|
|
|
}
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2007-04-03 13:04:29 +00:00
|
|
|
}
|
|
|
|
|
2003-03-26 15:47:28 +00:00
|
|
|
/**
|
|
|
|
Converts to an OString, signalling failure.
|
|
|
|
|
|
|
|
@param pTarget
|
|
|
|
An out parameter receiving the converted OString. Must not be null; the
|
|
|
|
contents are not modified if conversion fails (convertToOString returns
|
|
|
|
false).
|
|
|
|
|
|
|
|
@param nEncoding
|
|
|
|
The text encoding to convert into. Must be an octet encoding (i.e.,
|
|
|
|
rtl_isOctetTextEncoding(nEncoding) must return true).
|
|
|
|
|
|
|
|
@param nFlags
|
|
|
|
A combination of RTL_UNICODETOTEXT_FLAGS that detail how to do the
|
|
|
|
conversion (see rtl_convertUnicodeToText). RTL_UNICODETOTEXT_FLAGS_FLUSH
|
|
|
|
need not be included, it is implicitly assumed. Typical uses are either
|
|
|
|
RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR |
|
|
|
|
RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR (fail if a Unicode character cannot
|
|
|
|
be converted to the target nEncoding) or OUSTRING_TO_OSTRING_CVTFLAGS
|
|
|
|
(make a best efforts conversion).
|
|
|
|
|
|
|
|
@return
|
|
|
|
True if the conversion succeeded, false otherwise.
|
|
|
|
*/
|
|
|
|
inline bool convertToString(OString * pTarget, rtl_TextEncoding nEncoding,
|
2003-04-17 12:56:42 +00:00
|
|
|
sal_uInt32 nFlags) const
|
2003-03-26 15:47:28 +00:00
|
|
|
{
|
2003-04-17 12:56:42 +00:00
|
|
|
return rtl_convertUStringToString(&pTarget->pData, pData->buffer,
|
|
|
|
pData->length, nEncoding, nFlags);
|
2003-03-26 15:47:28 +00:00
|
|
|
}
|
|
|
|
|
2007-07-26 08:05:41 +00:00
|
|
|
/** Iterate through this string based on code points instead of UTF-16 code
|
|
|
|
units.
|
|
|
|
|
|
|
|
See Chapter 3 of The Unicode Standard 5.0 (Addison--Wesley, 2006) for
|
|
|
|
definitions of the various terms used in this description.
|
|
|
|
|
|
|
|
This string is interpreted as a sequence of zero or more UTF-16 code
|
|
|
|
units. For each index into this sequence (from zero to one less than
|
|
|
|
the length of the sequence, inclusive), a code point represented
|
|
|
|
starting at the given index is computed as follows:
|
|
|
|
|
|
|
|
- If the UTF-16 code unit addressed by the index constitutes a
|
|
|
|
well-formed UTF-16 code unit sequence, the computed code point is the
|
|
|
|
scalar value encoded by that UTF-16 code unit sequence.
|
|
|
|
|
|
|
|
- Otherwise, if the index is at least two UTF-16 code units away from
|
|
|
|
the end of the sequence, and the sequence of two UTF-16 code units
|
|
|
|
addressed by the index constitutes a well-formed UTF-16 code unit
|
|
|
|
sequence, the computed code point is the scalar value encoded by that
|
|
|
|
UTF-16 code unit sequence.
|
|
|
|
|
|
|
|
- Otherwise, the computed code point is the UTF-16 code unit addressed
|
|
|
|
by the index. (This last case catches unmatched surrogates as well as
|
|
|
|
indices pointing into the middle of surrogate pairs.)
|
|
|
|
|
|
|
|
@param indexUtf16
|
|
|
|
pointer to a UTF-16 based index into this string; must not be null. On
|
|
|
|
entry, the index must be in the range from zero to the length of this
|
|
|
|
string (in UTF-16 code units), inclusive. Upon successful return, the
|
|
|
|
index will be updated to address the UTF-16 code unit that is the given
|
|
|
|
incrementCodePoints away from the initial index.
|
|
|
|
|
|
|
|
@param incrementCodePoints
|
|
|
|
the number of code points to move the given *indexUtf16. If
|
|
|
|
non-negative, moving is done after determining the code point at the
|
|
|
|
index. If negative, moving is done before determining the code point
|
|
|
|
at the (then updated) index. The value must be such that the resulting
|
|
|
|
UTF-16 based index is in the range from zero to the length of this
|
|
|
|
string (in UTF-16 code units), inclusive.
|
|
|
|
|
|
|
|
@return
|
|
|
|
the code point (an integer in the range from 0 to 0x10FFFF, inclusive)
|
|
|
|
that is represented within this string starting at the index computed as
|
|
|
|
follows: If incrementCodePoints is non-negative, the index is the
|
|
|
|
initial value of *indexUtf16; if incrementCodePoints is negative, the
|
|
|
|
index is the updated value of *indexUtf16. In either case, the computed
|
|
|
|
index must be in the range from zero to one less than the length of this
|
|
|
|
string (in UTF-16 code units), inclusive.
|
|
|
|
|
|
|
|
@since UDK 3.2.7
|
|
|
|
*/
|
|
|
|
inline sal_uInt32 iterateCodePoints(
|
|
|
|
sal_Int32 * indexUtf16, sal_Int32 incrementCodePoints = 1) const
|
|
|
|
{
|
|
|
|
return rtl_uString_iterateCodePoints(
|
|
|
|
pData, indexUtf16, incrementCodePoints);
|
|
|
|
}
|
|
|
|
|
2014-11-05 12:07:44 +01:00
|
|
|
/**
|
|
|
|
* Convert an OString to an OUString, assuming that the OString is
|
|
|
|
* UTF-8-encoded.
|
|
|
|
*
|
2014-11-05 15:25:18 +01:00
|
|
|
* @param rSource
|
2014-11-05 12:07:44 +01:00
|
|
|
* an OString to convert
|
|
|
|
*
|
|
|
|
* @since LibreOffice 4.4
|
|
|
|
*/
|
2014-11-05 15:25:18 +01:00
|
|
|
static inline OUString fromUtf8(const OString& rSource)
|
|
|
|
{
|
|
|
|
OUString aTarget;
|
|
|
|
bool bSuccess = rtl_convertStringToUString(&aTarget.pData,
|
|
|
|
rSource.getStr(),
|
|
|
|
rSource.getLength(),
|
|
|
|
RTL_TEXTENCODING_UTF8,
|
|
|
|
RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR|RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR|RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR);
|
2014-11-05 18:50:03 +02:00
|
|
|
(void) bSuccess;
|
2014-11-05 15:25:18 +01:00
|
|
|
assert(bSuccess);
|
|
|
|
return aTarget;
|
2014-11-05 12:07:44 +01:00
|
|
|
}
|
|
|
|
|
2014-11-17 08:59:01 +01:00
|
|
|
/**
|
|
|
|
* Convert this string to an OString, assuming that the string can be
|
|
|
|
* UTF-8-encoded successfully.
|
|
|
|
*
|
|
|
|
* In other words, you must not use this method on a random sequence of
|
|
|
|
* UTF-16 code units, but only at places where it is assumed that the
|
|
|
|
* content is a proper string.
|
|
|
|
*
|
|
|
|
* @since LibreOffice 4.4
|
|
|
|
*/
|
|
|
|
inline OString toUtf8() const
|
|
|
|
{
|
|
|
|
OString aTarget;
|
|
|
|
bool bSuccess = rtl_convertUStringToString(&aTarget.pData,
|
|
|
|
getStr(),
|
|
|
|
getLength(),
|
|
|
|
RTL_TEXTENCODING_UTF8,
|
|
|
|
RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR|RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR);
|
|
|
|
(void) bSuccess;
|
|
|
|
assert(bSuccess);
|
|
|
|
return aTarget;
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
2013-01-28 18:19:19 +01:00
|
|
|
Returns the string representation of the integer argument.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
2013-01-28 18:19:19 +01:00
|
|
|
@param i an integer value
|
|
|
|
@param radix the radix (between 2 and 36)
|
2001-05-09 11:56:53 +00:00
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@since LibreOffice 4.1
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2013-01-28 18:19:19 +01:00
|
|
|
static OUString number( int i, sal_Int16 radix = 10 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
2013-01-28 18:19:19 +01:00
|
|
|
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFINT32];
|
2001-05-09 11:56:53 +00:00
|
|
|
rtl_uString* pNewData = 0;
|
2013-01-28 18:19:19 +01:00
|
|
|
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt32( aBuf, i, radix ) );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNewData, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
2013-01-28 18:19:19 +01:00
|
|
|
/// @overload
|
|
|
|
/// @since LibreOffice 4.1
|
|
|
|
static OUString number( unsigned int i, sal_Int16 radix = 10 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
2013-01-28 18:19:19 +01:00
|
|
|
return number( static_cast< unsigned long long >( i ), radix );
|
|
|
|
}
|
|
|
|
/// @overload
|
|
|
|
/// @since LibreOffice 4.1
|
|
|
|
static OUString number( long i, sal_Int16 radix = 10)
|
|
|
|
{
|
|
|
|
return number( static_cast< long long >( i ), radix );
|
|
|
|
}
|
|
|
|
/// @overload
|
|
|
|
/// @since LibreOffice 4.1
|
|
|
|
static OUString number( unsigned long i, sal_Int16 radix = 10 )
|
|
|
|
{
|
|
|
|
return number( static_cast< unsigned long long >( i ), radix );
|
|
|
|
}
|
|
|
|
/// @overload
|
|
|
|
/// @since LibreOffice 4.1
|
|
|
|
static OUString number( long long ll, sal_Int16 radix = 10 )
|
|
|
|
{
|
|
|
|
sal_Unicode aBuf[RTL_STR_MAX_VALUEOFINT64];
|
|
|
|
rtl_uString* pNewData = 0;
|
|
|
|
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfInt64( aBuf, ll, radix ) );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNewData, SAL_NO_ACQUIRE );
|
2013-01-28 18:19:19 +01:00
|
|
|
}
|
|
|
|
/// @overload
|
|
|
|
/// @since LibreOffice 4.1
|
|
|
|
static OUString number( unsigned long long ll, sal_Int16 radix = 10 )
|
|
|
|
{
|
|
|
|
sal_Unicode aBuf[RTL_STR_MAX_VALUEOFUINT64];
|
|
|
|
rtl_uString* pNewData = 0;
|
|
|
|
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfUInt64( aBuf, ll, radix ) );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNewData, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-28 18:19:19 +01:00
|
|
|
Returns the string representation of the float argument.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
2013-01-28 18:19:19 +01:00
|
|
|
@param f a float.
|
2001-05-09 11:56:53 +00:00
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@since LibreOffice 4.1
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2013-01-28 18:19:19 +01:00
|
|
|
static OUString number( float f )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
2013-01-28 18:19:19 +01:00
|
|
|
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFFLOAT];
|
2001-05-09 11:56:53 +00:00
|
|
|
rtl_uString* pNewData = 0;
|
2013-01-28 18:19:19 +01:00
|
|
|
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfFloat( aBuf, f ) );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNewData, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 09:37:14 +02:00
|
|
|
/**
|
2013-01-28 18:19:19 +01:00
|
|
|
Returns the string representation of the double argument.
|
2013-01-10 09:37:14 +02:00
|
|
|
|
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
2013-01-28 18:19:19 +01:00
|
|
|
@param d a double.
|
2013-01-10 09:37:14 +02:00
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@since LibreOffice 4.1
|
2013-01-10 09:37:14 +02:00
|
|
|
*/
|
2013-01-28 18:19:19 +01:00
|
|
|
static OUString number( double d )
|
2013-01-10 09:37:14 +02:00
|
|
|
{
|
2013-01-28 18:19:19 +01:00
|
|
|
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFDOUBLE];
|
2013-01-10 09:37:14 +02:00
|
|
|
rtl_uString* pNewData = 0;
|
2013-01-28 18:19:19 +01:00
|
|
|
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfDouble( aBuf, d ) );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNewData, SAL_NO_ACQUIRE );
|
2013-01-10 09:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-28 18:19:19 +01:00
|
|
|
Returns the string representation of the sal_Bool argument.
|
2013-01-10 09:37:14 +02:00
|
|
|
|
2013-01-28 18:19:19 +01:00
|
|
|
If the sal_Bool is true, the string "true" is returned.
|
|
|
|
If the sal_Bool is false, the string "false" is returned.
|
2013-01-10 09:37:14 +02:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
2013-01-28 18:19:19 +01:00
|
|
|
@param b a sal_Bool.
|
2013-01-10 09:37:14 +02:00
|
|
|
@return a string with the string representation of the argument.
|
2013-02-04 11:40:14 +01:00
|
|
|
@deprecated use boolean()
|
2013-01-10 09:37:14 +02:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_DEPRECATED("use boolean()") static OUString valueOf( sal_Bool b )
|
2013-02-04 11:40:14 +01:00
|
|
|
{
|
|
|
|
return boolean(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the string representation of the boolean argument.
|
|
|
|
|
2013-02-04 14:57:21 +01:00
|
|
|
If the argument is true, the string "true" is returned.
|
|
|
|
If the argument is false, the string "false" is returned.
|
2013-02-04 11:40:14 +01:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
2013-02-04 14:44:24 +01:00
|
|
|
@param b a bool.
|
2013-02-04 11:40:14 +01:00
|
|
|
@return a string with the string representation of the argument.
|
|
|
|
@since LibreOffice 4.1
|
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
static OUString boolean( bool b )
|
2013-01-10 09:37:14 +02:00
|
|
|
{
|
2013-01-28 18:19:19 +01:00
|
|
|
sal_Unicode aBuf[RTL_USTR_MAX_VALUEOFBOOLEAN];
|
2013-01-10 09:37:14 +02:00
|
|
|
rtl_uString* pNewData = 0;
|
2013-01-28 18:19:19 +01:00
|
|
|
rtl_uString_newFromStr_WithLength( &pNewData, aBuf, rtl_ustr_valueOfBoolean( aBuf, b ) );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNewData, SAL_NO_ACQUIRE );
|
2013-01-10 09:37:14 +02:00
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
2013-01-28 18:19:19 +01:00
|
|
|
Returns the string representation of the char argument.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2013-01-28 18:19:19 +01:00
|
|
|
@param c a character.
|
2001-05-09 11:56:53 +00:00
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@deprecated use operator, function or constructor taking char or sal_Unicode argument
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_DEPRECATED("convert to OUString or use directly") static OUString valueOf( sal_Unicode c )
|
2013-01-10 09:37:14 +02:00
|
|
|
{
|
2013-01-28 18:19:19 +01:00
|
|
|
return OUString( &c, 1 );
|
2013-01-10 09:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-28 18:19:19 +01:00
|
|
|
Returns the string representation of the int argument.
|
2013-01-10 09:37:14 +02:00
|
|
|
|
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
2013-01-28 18:19:19 +01:00
|
|
|
@param i a int32.
|
2013-01-10 09:37:14 +02:00
|
|
|
@param radix the radix (between 2 and 36)
|
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@deprecated use number()
|
2013-01-10 09:37:14 +02:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int32 i, sal_Int16 radix = 10 )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
2013-02-05 11:39:06 +01:00
|
|
|
return number( i, radix );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 09:37:14 +02:00
|
|
|
/**
|
|
|
|
Returns the string representation of the long argument.
|
|
|
|
|
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@param ll a int64.
|
|
|
|
@param radix the radix (between 2 and 36)
|
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@deprecated use number()
|
2013-01-10 09:37:14 +02:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_DEPRECATED("use number()") static OUString valueOf( sal_Int64 ll, sal_Int16 radix = 10 )
|
2013-01-10 09:37:14 +02:00
|
|
|
{
|
2013-01-28 18:19:19 +01:00
|
|
|
return number( ll, radix );
|
2013-01-10 09:37:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the string representation of the float argument.
|
|
|
|
|
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@param f a float.
|
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@deprecated use number()
|
2013-01-10 09:37:14 +02:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_DEPRECATED("use number()") static OUString valueOf( float f )
|
2013-01-10 09:37:14 +02:00
|
|
|
{
|
|
|
|
return number(f);
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns the string representation of the double argument.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
This function can't be used for language specific conversion.
|
|
|
|
|
|
|
|
@param d a double.
|
|
|
|
@return a string with the string representation of the argument.
|
2013-01-28 18:19:19 +01:00
|
|
|
@deprecated use number()
|
2013-01-10 09:37:14 +02:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
SAL_DEPRECATED("use number()") static OUString valueOf( double d )
|
2013-01-10 09:37:14 +02:00
|
|
|
{
|
|
|
|
return number(d);
|
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/**
|
|
|
|
Returns a OUString copied without conversion from an ASCII
|
|
|
|
character string.
|
2001-10-30 12:41:07 +00:00
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
Since this method is optimized for performance, the ASCII character
|
|
|
|
values are not converted in any way. The caller has to make sure that
|
|
|
|
all ASCII characters are in the allowed range between 0 and
|
|
|
|
127. The ASCII string must be NULL-terminated.
|
2001-05-09 11:56:53 +00:00
|
|
|
|
2012-02-22 15:35:41 +01:00
|
|
|
Note that for string literals it is simpler and more efficient
|
|
|
|
to directly use the OUString constructor.
|
|
|
|
|
2001-07-27 12:26:37 +00:00
|
|
|
@param value the 8-Bit ASCII character string
|
|
|
|
@return a string with the string representation of the argument.
|
2001-05-09 11:56:53 +00:00
|
|
|
*/
|
2014-06-05 08:10:23 +02:00
|
|
|
static OUString createFromAscii( const sal_Char * value )
|
2001-05-09 11:56:53 +00:00
|
|
|
{
|
|
|
|
rtl_uString* pNew = 0;
|
|
|
|
rtl_uString_newFromAscii( &pNew, value );
|
2013-05-23 08:46:40 +02:00
|
|
|
return OUString( pNew, SAL_NO_ACQUIRE );
|
2001-05-09 11:56:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-12-19 12:01:42 +01:00
|
|
|
#if defined LIBO_INTERNAL_ONLY // "RTL_FAST_STRING"
|
2014-12-17 15:47:01 +01:00
|
|
|
/// @cond INTERNAL
|
|
|
|
|
|
|
|
/** Compare a string and an ASCII character literal for equality.
|
|
|
|
|
2015-04-10 11:50:37 +02:00
|
|
|
@since LibreOffice 5.0
|
2014-12-17 15:47:01 +01:00
|
|
|
*/
|
|
|
|
template<char C> bool operator ==(OUString const & string, OUStringLiteral1<C>)
|
|
|
|
{
|
|
|
|
char const c = C;
|
|
|
|
return string.equalsAsciiL(&c, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Compare a string and an ASCII character literal for inequality.
|
|
|
|
|
2015-04-10 11:50:37 +02:00
|
|
|
@since LibreOffice 5.0
|
2014-12-17 15:47:01 +01:00
|
|
|
*/
|
|
|
|
template<char C> bool operator !=(
|
|
|
|
OUString const & string, OUStringLiteral1<C> literal)
|
|
|
|
{
|
|
|
|
return !(string == literal);
|
|
|
|
}
|
|
|
|
|
2012-12-04 18:11:12 +01:00
|
|
|
/**
|
|
|
|
@internal
|
|
|
|
*/
|
2012-12-02 22:29:21 +01:00
|
|
|
template<>
|
|
|
|
struct ToStringHelper< OUString >
|
|
|
|
{
|
|
|
|
static int length( const OUString& s ) { return s.getLength(); }
|
|
|
|
static sal_Unicode* addData( sal_Unicode* buffer, const OUString& s ) { return addDataHelper( buffer, s.getStr(), s.getLength()); }
|
|
|
|
static const bool allowOStringConcat = false;
|
|
|
|
static const bool allowOUStringConcat = true;
|
|
|
|
};
|
|
|
|
|
2012-12-04 18:11:12 +01:00
|
|
|
/**
|
|
|
|
@internal
|
|
|
|
*/
|
2012-12-02 22:29:21 +01:00
|
|
|
template<>
|
|
|
|
struct ToStringHelper< OUStringLiteral >
|
|
|
|
{
|
|
|
|
static int length( const OUStringLiteral& str ) { return str.size; }
|
|
|
|
static sal_Unicode* addData( sal_Unicode* buffer, const OUStringLiteral& str ) { return addDataLiteral( buffer, str.data, str.size ); }
|
|
|
|
static const bool allowOStringConcat = false;
|
|
|
|
static const bool allowOUStringConcat = true;
|
|
|
|
};
|
|
|
|
|
2014-12-17 15:47:01 +01:00
|
|
|
/**
|
|
|
|
@internal
|
|
|
|
*/
|
|
|
|
template<char C> struct ToStringHelper<OUStringLiteral1<C>>
|
|
|
|
{
|
|
|
|
static int length(OUStringLiteral1<C>) { return 1; }
|
|
|
|
static sal_Unicode * addData(sal_Unicode * buffer, OUStringLiteral1<C>)
|
|
|
|
{ *buffer++ = C; return buffer; }
|
|
|
|
static const bool allowOStringConcat = false;
|
|
|
|
static const bool allowOUStringConcat = true;
|
|
|
|
};
|
|
|
|
|
2012-12-04 18:11:12 +01:00
|
|
|
/**
|
|
|
|
@internal
|
|
|
|
*/
|
2012-12-02 22:29:21 +01:00
|
|
|
template< typename charT, typename traits, typename T1, typename T2 >
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(
|
|
|
|
std::basic_ostream<charT, traits> & stream, const OUStringConcat< T1, T2 >& concat)
|
|
|
|
{
|
|
|
|
return stream << OUString( concat );
|
|
|
|
}
|
2014-12-19 12:01:42 +01:00
|
|
|
|
2013-05-29 15:01:18 +02:00
|
|
|
/// @endcond
|
2012-12-02 22:29:21 +01:00
|
|
|
#endif
|
|
|
|
|
2001-10-30 12:41:07 +00:00
|
|
|
/** A helper to use OUStrings with hash maps.
|
|
|
|
|
|
|
|
Instances of this class are unary function objects that can be used as
|
2015-01-07 13:45:54 +00:00
|
|
|
hash function arguments to std::unordered_map and similar constructs.
|
2001-10-30 12:41:07 +00:00
|
|
|
*/
|
2001-05-09 11:56:53 +00:00
|
|
|
struct OUStringHash
|
2000-09-18 14:18:43 +00:00
|
|
|
{
|
2001-10-30 12:41:07 +00:00
|
|
|
/** Compute a hash code for a string.
|
|
|
|
|
|
|
|
@param rString
|
|
|
|
a string.
|
|
|
|
|
|
|
|
@return
|
|
|
|
a hash code for the string. This hash code should not be stored
|
|
|
|
persistently, as its computation may change in later revisions.
|
|
|
|
*/
|
2012-03-28 21:33:11 +02:00
|
|
|
size_t operator()(const OUString& rString) const
|
2001-05-09 11:56:53 +00:00
|
|
|
{ return (size_t)rString.hashCode(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ======================================================================= */
|
2000-09-18 14:18:43 +00:00
|
|
|
|
2001-10-30 12:41:07 +00:00
|
|
|
/** Convert an OString to an OUString, using a specific text encoding.
|
|
|
|
|
|
|
|
The lengths of the two strings may differ (e.g., for double-byte
|
|
|
|
encodings, UTF-7, UTF-8).
|
|
|
|
|
|
|
|
@param rStr
|
|
|
|
an OString to convert.
|
|
|
|
|
|
|
|
@param encoding
|
|
|
|
the text encoding to use for conversion.
|
|
|
|
|
|
|
|
@param convertFlags
|
|
|
|
flags which control the conversion. Either use
|
|
|
|
OSTRING_TO_OUSTRING_CVTFLAGS, or see
|
|
|
|
<http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
|
|
|
|
details.
|
|
|
|
*/
|
2000-09-18 14:18:43 +00:00
|
|
|
inline OUString OStringToOUString( const OString & rStr,
|
|
|
|
rtl_TextEncoding encoding,
|
2001-03-16 14:17:03 +00:00
|
|
|
sal_uInt32 convertFlags = OSTRING_TO_OUSTRING_CVTFLAGS )
|
2000-09-18 14:18:43 +00:00
|
|
|
{
|
2001-03-19 10:39:33 +00:00
|
|
|
return OUString( rStr.getStr(), rStr.getLength(), encoding, convertFlags );
|
2000-09-18 14:18:43 +00:00
|
|
|
}
|
|
|
|
|
2001-10-30 12:41:07 +00:00
|
|
|
/** Convert an OUString to an OString, using a specific text encoding.
|
|
|
|
|
|
|
|
The lengths of the two strings may differ (e.g., for double-byte
|
|
|
|
encodings, UTF-7, UTF-8).
|
|
|
|
|
2012-02-22 00:50:56 +01:00
|
|
|
@param rUnicode
|
2001-10-30 12:41:07 +00:00
|
|
|
an OUString to convert.
|
|
|
|
|
|
|
|
@param encoding
|
|
|
|
the text encoding to use for conversion.
|
|
|
|
|
|
|
|
@param convertFlags
|
|
|
|
flags which control the conversion. Either use
|
|
|
|
OUSTRING_TO_OSTRING_CVTFLAGS, or see
|
|
|
|
<http://udk.openoffice.org/cpp/man/spec/textconversion.html> for more
|
|
|
|
details.
|
|
|
|
*/
|
2000-09-18 14:18:43 +00:00
|
|
|
inline OString OUStringToOString( const OUString & rUnicode,
|
|
|
|
rtl_TextEncoding encoding,
|
2001-03-16 14:17:03 +00:00
|
|
|
sal_uInt32 convertFlags = OUSTRING_TO_OSTRING_CVTFLAGS )
|
2000-09-18 14:18:43 +00:00
|
|
|
{
|
2001-03-19 10:39:33 +00:00
|
|
|
return OString( rUnicode.getStr(), rUnicode.getLength(), encoding, convertFlags );
|
2000-09-18 14:18:43 +00:00
|
|
|
}
|
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
/* ======================================================================= */
|
|
|
|
|
2012-09-18 11:54:05 +02:00
|
|
|
/**
|
|
|
|
Support for rtl::OUString in std::ostream (and thus in
|
|
|
|
CPPUNIT_ASSERT or SAL_INFO macros, for example).
|
|
|
|
|
|
|
|
The rtl::OUString is converted to UTF-8.
|
|
|
|
|
|
|
|
@since LibreOffice 3.5.
|
|
|
|
*/
|
|
|
|
template< typename charT, typename traits >
|
|
|
|
inline std::basic_ostream<charT, traits> & operator <<(
|
|
|
|
std::basic_ostream<charT, traits> & stream, OUString const & string)
|
|
|
|
{
|
|
|
|
return stream <<
|
2012-12-04 17:44:43 +01:00
|
|
|
OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr();
|
2012-09-18 11:54:05 +02:00
|
|
|
// best effort; potentially loses data due to conversion failures
|
|
|
|
// (stray surrogate halves) and embedded null characters
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2012-12-04 17:44:43 +01:00
|
|
|
#ifdef RTL_STRING_UNITTEST
|
|
|
|
namespace rtl
|
|
|
|
{
|
|
|
|
typedef rtlunittest::OUString OUString;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-19 11:43:51 +01:00
|
|
|
// In internal code, allow to use classes like OUString without having to
|
|
|
|
// explicitly refer to the rtl namespace, which is kind of superfluous given
|
|
|
|
// that OUString itself is namespaced by its OU prefix:
|
2014-12-19 12:01:42 +01:00
|
|
|
#if defined LIBO_INTERNAL_ONLY && !defined RTL_STRING_UNITTEST
|
2012-07-16 14:33:06 +02:00
|
|
|
using ::rtl::OUString;
|
|
|
|
using ::rtl::OUStringHash;
|
|
|
|
using ::rtl::OStringToOUString;
|
|
|
|
using ::rtl::OUStringToOString;
|
2012-12-02 22:29:21 +01:00
|
|
|
using ::rtl::OUStringLiteral;
|
2014-12-17 15:47:01 +01:00
|
|
|
using ::rtl::OUStringLiteral1;
|
|
|
|
#endif
|
2012-07-16 14:33:06 +02:00
|
|
|
|
2001-05-09 11:56:53 +00:00
|
|
|
#endif /* _RTL_USTRING_HXX */
|
2010-10-14 08:30:07 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|