2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2000-09-18 16:07:07 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 13:02:13 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 13:02:13 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 13:02:13 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 13:02:13 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 13:02:13 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
2008-04-11 13:02:13 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2000-09-18 16:07:07 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-17 00:04:40 +00:00
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-08-13 16:23:23 +00:00
|
|
|
#include "osl/diagnose.h"
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <osl/interlck.h>
|
|
|
|
#include <rtl/alloc.h>
|
|
|
|
#include <rtl/memory.h>
|
|
|
|
#include <rtl/tencinfo.h>
|
|
|
|
|
2007-06-27 21:20:00 +00:00
|
|
|
#include <tools/string.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
#include <impstrg.hxx>
|
|
|
|
|
2007-06-27 21:20:00 +00:00
|
|
|
#include <tools/debug.hxx>
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
|
2006-06-19 12:53:39 +00:00
|
|
|
DBG_NAME( ByteString )
|
|
|
|
DBG_NAMEEX( UniString )
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define STRCODE sal_Char
|
2006-06-19 12:53:39 +00:00
|
|
|
#define STRCODEU unsigned char
|
2000-09-18 16:07:07 +00:00
|
|
|
#define STRING ByteString
|
|
|
|
#define STRINGDATA ByteStringData
|
|
|
|
#define DBGCHECKSTRING DbgCheckByteString
|
2006-05-04 13:53:13 +00:00
|
|
|
#define STRING_TYPE rtl_String
|
|
|
|
#define STRING_ACQUIRE rtl_string_acquire
|
|
|
|
#define STRING_RELEASE rtl_string_release
|
|
|
|
#define STRING_NEW rtl_string_new
|
|
|
|
|
2000-09-18 16:07:07 +00:00
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
xub_StrLen ImplStringLen( const sal_Char* pStr )
|
|
|
|
{
|
|
|
|
const sal_Char* pTempStr = pStr;
|
|
|
|
while( *pTempStr )
|
2003-03-27 16:05:12 +00:00
|
|
|
++pTempStr;
|
2000-09-18 16:07:07 +00:00
|
|
|
return (xub_StrLen)(pTempStr-pStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
xub_StrLen ImplStringLen( const sal_Unicode* pStr )
|
|
|
|
{
|
|
|
|
const sal_Unicode* pTempStr = pStr;
|
|
|
|
while( *pTempStr )
|
2003-03-27 16:05:12 +00:00
|
|
|
++pTempStr;
|
2000-09-18 16:07:07 +00:00
|
|
|
return (xub_StrLen)(pTempStr-pStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <strimp.cxx>
|
|
|
|
#include <strcvt.cxx>
|
|
|
|
|
2011-07-26 01:13:31 +01:00
|
|
|
xub_StrLen STRING::SearchAndReplace( const STRCODE* pCharStr, const STRING& rRepStr,
|
|
|
|
xub_StrLen nIndex )
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS( STRING, DBGCHECKSTRING );
|
|
|
|
DBG_CHKOBJ( &rRepStr, STRING, DBGCHECKSTRING );
|
|
|
|
|
|
|
|
xub_StrLen nSPos = Search( pCharStr, nIndex );
|
|
|
|
if ( nSPos != STRING_NOTFOUND )
|
|
|
|
Replace( nSPos, ImplStringLen( pCharStr ), rRepStr );
|
|
|
|
|
|
|
|
return nSPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static sal_Int32 ImplStringICompare( const STRCODE* pStr1, const STRCODE* pStr2,
|
|
|
|
xub_StrLen nCount )
|
|
|
|
{
|
|
|
|
sal_Int32 nRet = 0;
|
|
|
|
STRCODE c1;
|
|
|
|
STRCODE c2;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if ( !nCount )
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Ist das Zeichen zwischen 'A' und 'Z' dann umwandeln
|
|
|
|
c1 = *pStr1;
|
|
|
|
c2 = *pStr2;
|
|
|
|
if ( (c1 >= 65) && (c1 <= 90) )
|
|
|
|
c1 += 32;
|
|
|
|
if ( (c2 >= 65) && (c2 <= 90) )
|
|
|
|
c2 += 32;
|
|
|
|
nRet = ((sal_Int32)((STRCODEU)c1))-((sal_Int32)((STRCODEU)c2));
|
|
|
|
if ( nRet != 0 )
|
|
|
|
break;
|
|
|
|
|
|
|
|
++pStr1,
|
|
|
|
++pStr2,
|
|
|
|
--nCount;
|
|
|
|
}
|
|
|
|
while ( c2 );
|
|
|
|
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringCompare STRING::CompareIgnoreCaseToAscii( const STRCODE* pCharStr,
|
|
|
|
xub_StrLen nLen ) const
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS( STRING, DBGCHECKSTRING );
|
|
|
|
|
|
|
|
// String vergleichen
|
|
|
|
sal_Int32 nCompare = ImplStringICompare( mpData->maStr, pCharStr, nLen );
|
|
|
|
|
|
|
|
// Rueckgabewert anpassen
|
|
|
|
if ( nCompare == 0 )
|
|
|
|
return COMPARE_EQUAL;
|
|
|
|
else if ( nCompare < 0 )
|
|
|
|
return COMPARE_LESS;
|
|
|
|
else
|
|
|
|
return COMPARE_GREATER;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringCompare STRING::CompareTo( const STRCODE* pCharStr, xub_StrLen nLen ) const
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS( STRING, DBGCHECKSTRING );
|
|
|
|
|
|
|
|
// String vergleichen
|
|
|
|
sal_Int32 nCompare = ImplStringCompare( mpData->maStr, pCharStr, nLen );
|
|
|
|
|
|
|
|
// Rueckgabewert anpassen
|
|
|
|
if ( nCompare == 0 )
|
|
|
|
return COMPARE_EQUAL;
|
|
|
|
else if ( nCompare < 0 )
|
|
|
|
return COMPARE_LESS;
|
|
|
|
else
|
|
|
|
return COMPARE_GREATER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// =======================================================================
|
|
|
|
|
|
|
|
static sal_Int32 ImplStringCompare( const STRCODE* pStr1, const STRCODE* pStr2 )
|
|
|
|
{
|
|
|
|
sal_Int32 nRet;
|
|
|
|
while ( ((nRet = ((sal_Int32)((STRCODEU)*pStr1))-((sal_Int32)((STRCODEU)*pStr2))) == 0) &&
|
|
|
|
*pStr2 )
|
|
|
|
{
|
|
|
|
++pStr1,
|
|
|
|
++pStr2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool STRING::Equals( const STRCODE* pCharStr ) const
|
|
|
|
{
|
|
|
|
DBG_CHKTHIS( STRING, DBGCHECKSTRING );
|
|
|
|
|
|
|
|
return (ImplStringCompare( mpData->maStr, pCharStr ) == 0);
|
|
|
|
}
|
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|