mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-13 08:53:20 +00:00
ICU-6765 add std_string.h with central #include <string> and std:: namespace definitions
X-SVN-Rev: 25479
This commit is contained in:
parent
1d91a19628
commit
59d37b352b
4 changed files with 131 additions and 2 deletions
|
@ -1168,6 +1168,10 @@
|
|||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\unicode\std_string.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\uassert.h"
|
||||
>
|
||||
|
|
78
icu4c/source/common/unicode/std_string.h
Normal file
78
icu4c/source/common/unicode/std_string.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
*
|
||||
* Copyright (C) 2009, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*
|
||||
*******************************************************************************
|
||||
* file name: std_string.h
|
||||
* encoding: US-ASCII
|
||||
* tab size: 8 (not used)
|
||||
* indentation:4
|
||||
*
|
||||
* created on: 2009feb19
|
||||
* created by: Markus W. Scherer
|
||||
*/
|
||||
|
||||
#ifndef __STD_STRING_H__
|
||||
#define __STD_STRING_H__
|
||||
|
||||
/**
|
||||
* \file
|
||||
* \brief C++ API: Central ICU header for including the C++ standard <string>
|
||||
* header and for related definitions.
|
||||
*/
|
||||
|
||||
#include "unicode/utypes.h"
|
||||
|
||||
/**
|
||||
* \def U_HAVE_STD_STRING
|
||||
* Define whether the standard C++ (STL) <string> header is available.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
#ifndef U_HAVE_STD_STRING
|
||||
#define U_HAVE_STD_STRING 1
|
||||
#endif
|
||||
|
||||
#if U_HAVE_STD_STRING
|
||||
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* \def U_STD_NS
|
||||
* Define the namespace to use for standard C++ (STL) classes.
|
||||
* Either std or empty.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def U_STD_NSQ
|
||||
* Define the namespace qualifier to use for standard C++ (STL) classes.
|
||||
* Either std:: or empty.
|
||||
* For example,
|
||||
* U_STD_NSQ string StringFromUnicodeString(const UnicodeString &unistr);
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
|
||||
/**
|
||||
* \def U_STD_NS_USE
|
||||
* This is used to specify that the rest of the code uses the
|
||||
* standard (STL) namespace.
|
||||
* Either "using namespace std;" or empty.
|
||||
* @draft ICU 4.2
|
||||
*/
|
||||
#ifndef U_STD_NSQ
|
||||
# if U_HAVE_NAMESPACE
|
||||
# define U_STD_NS std
|
||||
# define U_STD_NSQ U_STD_NS::
|
||||
# define U_STD_NS_USE using namespace U_STD_NS;
|
||||
# else
|
||||
# define U_STD_NS
|
||||
# define U_STD_NSQ
|
||||
# define U_STD_NS_USE
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // U_HAVE_STD_STRING
|
||||
|
||||
#endif // __STD_STRING_H__
|
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2005, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2009, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/* file name: strtest.cpp
|
||||
|
@ -185,8 +185,52 @@ void StringTest::runIndexedTest(int32_t index, UBool exec, const char *&name, ch
|
|||
#endif
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
name="TestStdNamespaceQualifier";
|
||||
if(exec) {
|
||||
TestStdNamespaceQualifier();
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
name="TestUsingStdNamespace";
|
||||
if(exec) {
|
||||
TestUsingStdNamespace();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
name="";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Syntax check for the correct namespace qualifier for the standard string class.
|
||||
void
|
||||
StringTest::TestStdNamespaceQualifier() {
|
||||
#if U_HAVE_STD_STRING
|
||||
U_STD_NSQ string s="abc xyz";
|
||||
U_STD_NSQ string t="abc";
|
||||
t.append(" ");
|
||||
t.append("xyz");
|
||||
if(s!=t) {
|
||||
errln("standard string concatenation error: %s != %s", s.c_str(), t.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if U_HAVE_STD_STRING
|
||||
// Now test that "using namespace std;" is defined correctly.
|
||||
U_STD_NS_USE
|
||||
#endif
|
||||
|
||||
void
|
||||
StringTest::TestUsingStdNamespace() {
|
||||
#if U_HAVE_STD_STRING
|
||||
string s="abc xyz";
|
||||
string t="abc";
|
||||
t.append(" ");
|
||||
t.append("xyz");
|
||||
if(s!=t) {
|
||||
errln("standard string concatenation error: %s != %s", s.c_str(), t.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/********************************************************************
|
||||
* COPYRIGHT:
|
||||
* Copyright (c) 1997-2004, International Business Machines Corporation and
|
||||
* Copyright (c) 1997-2009, International Business Machines Corporation and
|
||||
* others. All Rights Reserved.
|
||||
********************************************************************/
|
||||
/* file name: strtest.h
|
||||
|
@ -15,6 +15,7 @@
|
|||
/*
|
||||
* Test character- and string- related settings in utypes.h,
|
||||
* macros in putil.h, and constructors in unistr.h .
|
||||
* Also basic tests for std_string.h .
|
||||
*/
|
||||
|
||||
#ifndef __STRTEST_H__
|
||||
|
@ -33,6 +34,8 @@ private:
|
|||
void TestEndian(void);
|
||||
void TestSizeofTypes(void);
|
||||
void TestCharsetFamily(void);
|
||||
void TestStdNamespaceQualifier();
|
||||
void TestUsingStdNamespace();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue