ICU-4466 update samples for ICU 3.3

X-SVN-Rev: 17432
This commit is contained in:
Eric Mader 2005-03-31 19:19:21 +00:00
parent d0f1a428a7
commit 5997f5c628
7 changed files with 310 additions and 152 deletions

View File

@ -83,6 +83,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "writer", "..\udata\writer.v
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "citer", "..\citer\citer.vcproj", "{247E2681-6C84-408B-B40C-5DB50BC5E18F}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
@ -173,6 +177,10 @@ Global
{45D0BE49-661A-41A5-AD81-986655688801}.Debug.Build.0 = Debug|Win32
{45D0BE49-661A-41A5-AD81-986655688801}.Release.ActiveCfg = Release|Win32
{45D0BE49-661A-41A5-AD81-986655688801}.Release.Build.0 = Release|Win32
{247E2681-6C84-408B-B40C-5DB50BC5E18F}.Debug.ActiveCfg = Debug|Win32
{247E2681-6C84-408B-B40C-5DB50BC5E18F}.Debug.Build.0 = Debug|Win32
{247E2681-6C84-408B-B40C-5DB50BC5E18F}.Release.ActiveCfg = Release|Win32
{247E2681-6C84-408B-B40C-5DB50BC5E18F}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection

View File

@ -1,8 +1,8 @@
/*
*******************************************************************************
*
* Copyright (C) 2002-2003, International Business Machines
* Corporation and others. All Rights Reserved.
* Copyright (C) 2002-2005, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
*/
@ -11,173 +11,185 @@
#include "unicode/schriter.h"
#include "unicode/ustring.h"
#include <stdio.h>
#include <iostream.h>
#include <unicode/brkiter.h>
#include <unicode/ustdio.h>
#include <stdlib.h>
void printUnicodeString(const UnicodeString &s) {
char charBuf[1000];
s.extract(0, s.length(), charBuf, sizeof(charBuf)-1, 0);
charBuf[sizeof(charBuf)-1] = 0;
cout << charBuf;
static UFILE *out;
void printUnicodeString(const UnicodeString &s)
{
u_fprintf(out, "%S", s);
}
void printUChar(UChar32 ch) {
char charBuf[1000];
charBuf[sizeof(charBuf)-1] = 0;
if(ch < 127) {
cout << (char) ch;
} else if (ch == CharacterIterator::DONE) {
cout << "[CharacterIterator::DONE = 0xFFFF]";
} else {
cout << "[" << ch << "]";
}
void printUChar(UChar32 ch)
{
if(ch < 127) {
u_fprintf(out, "%C", (UChar) ch);
} else if (ch == CharacterIterator::DONE) {
u_fprintf(out, "[CharacterIterator::DONE = 0xFFFF]");
} else {
u_fprintf(out, "[%X]", ch);
}
}
class Test
{
public:
void TestUChariter();
void TestStringiter();
void TestUChariter();
void TestStringiter();
};
void Test::TestUChariter() {
const char testChars[] = "Now is the time for all good men to come "
"to the aid of their country.";
const char testChars[] = "Now is the time for all good men to come "
"to the aid of their country.";
UnicodeString testString(testChars,"");
const UChar *testText = testString.getTerminatedBuffer();
UnicodeString testString(testChars,"");
const UChar *testText = testString.getTerminatedBuffer();
UCharCharacterIterator iter(testText, u_strlen(testText));
UCharCharacterIterator* test2 = (UCharCharacterIterator*)iter.clone();
cout << "testText = " << testChars;
if (iter != *test2 ) {
printf("clone() or equals() failed: Two clones tested unequal\n");
}
UnicodeString result1, result2;
// getting and comparing the text within the iterators
iter.getText(result1);
test2->getText(result2);
if (result1 != result2) {
printf("iter.getText() != clone.getText()\n");
}
cout << endl;
// Demonstrates seeking forward using the iterator.
cout << "Forward = ";
UChar c = iter.first();
printUChar(c); // The first char
int32_t i = 0;
if (iter.startIndex() != 0 || iter.endIndex() != u_strlen(testText)) {
printf("startIndex() or endIndex() failed\n");
}
// Testing forward iteration...
do {
if (c == CharacterIterator::DONE && i != u_strlen(testText)) {
printf("Iterator reached end prematurely");
}
else if (c != testText[i]) {
printf("Character mismatch at position %d\n" + i);
}
if (iter.current() != c) {
printf("current() isn't working right");
}
if (iter.getIndex() != i) {
printf("getIndex() isn't working right\n");
}
if (c != CharacterIterator::DONE) {
c = iter.next();
i++;
UCharCharacterIterator iter(testText, u_strlen(testText));
UCharCharacterIterator* test2 = (UCharCharacterIterator*)iter.clone();
u_fprintf(out, "testText = %s", testChars);
if (iter != *test2 ) {
printf("clone() or equals() failed: Two clones tested unequal\n");
}
cout << "|";
printUChar(c);
UnicodeString result1, result2;
// getting and comparing the text within the iterators
iter.getText(result1);
test2->getText(result2);
if (result1 != result2) {
printf("iter.getText() != clone.getText()\n");
}
u_fprintf(out, "\n");
// Demonstrates seeking forward using the iterator.
u_fprintf(out, "Forward = ");
UChar c = iter.first();
printUChar(c); // The first char
int32_t i = 0;
if (iter.startIndex() != 0 || iter.endIndex() != u_strlen(testText)) {
printf("startIndex() or endIndex() failed\n");
}
// Testing forward iteration...
do {
if (c == CharacterIterator::DONE && i != u_strlen(testText)) {
printf("Iterator reached end prematurely");
}
else if (c != testText[i]) {
printf("Character mismatch at position %d\n" + i);
}
if (iter.current() != c) {
printf("current() isn't working right");
}
if (iter.getIndex() != i) {
printf("getIndex() isn't working right\n");
}
if (c != CharacterIterator::DONE) {
c = iter.next();
i++;
}
} while (c != CharacterIterator::DONE);
delete test2;
cout << endl;
u_fprintf(out, "|");
printUChar(c);
} while (c != CharacterIterator::DONE);
delete test2;
u_fprintf(out, "\n");
}
void Test::TestStringiter() {
const char testChars[] = "Now is the time for all good men to come "
"to the aid of their country.";
const char testChars[] = "Now is the time for all good men to come "
"to the aid of their country.";
UnicodeString testString(testChars,"");
const UChar *testText = testString.getTerminatedBuffer();
StringCharacterIterator iter(testText, u_strlen(testText));
StringCharacterIterator* test2 = (StringCharacterIterator*)iter.clone();
if (iter != *test2 ) {
printf("clone() or equals() failed: Two clones tested unequal\n");
}
UnicodeString result1, result2;
// getting and comparing the text within the iterators
iter.getText(result1);
test2->getText(result2);
if (result1 != result2) {
printf("getText() failed\n");
}
UnicodeString testString(testChars,"");
const UChar *testText = testString.getTerminatedBuffer();
StringCharacterIterator iter(testText, u_strlen(testText));
StringCharacterIterator* test2 = (StringCharacterIterator*)iter.clone();
if (iter != *test2 ) {
printf("clone() or equals() failed: Two clones tested unequal\n");
}
UnicodeString result1, result2;
// getting and comparing the text within the iterators
iter.getText(result1);
test2->getText(result2);
if (result1 != result2) {
printf("getText() failed\n");
}
u_fprintf(out, "Backwards: ");
UChar c = iter.last();
int32_t i = iter.endIndex();
cout << "Backwards: ";
UChar c = iter.last();
printUChar(c);
int32_t i = iter.endIndex();
i--; // already printed out the last char
if (iter.startIndex() != 0 || iter.endIndex() != u_strlen(testText)) {
printf("startIndex() or endIndex() failed\n");
}
// Testing backward iteration over a range...
do {
if (c == CharacterIterator::DONE) {
printf("Iterator reached end prematurely\n");
}
else if (c != testText[i]) {
printf("Character mismatch at position %d\n" + i);
}
if (iter.current() != c) {
printf("current() isn't working right\n");
}
if (iter.getIndex() != i) {
printf("getIndex() isn't working right [%d should be %d]\n", iter.getIndex(), i);
}
if (c != CharacterIterator::DONE) {
c = iter.previous();
i--;
}
cout << "|";
printUChar(c);
} while (c != CharacterIterator::DONE);
i--; // already printed out the last char
cout << endl;
delete test2;
if (iter.startIndex() != 0 || iter.endIndex() != u_strlen(testText)) {
printf("startIndex() or endIndex() failed\n");
}
// Testing backward iteration over a range...
do {
if (c == CharacterIterator::DONE) {
printf("Iterator reached end prematurely\n");
}
else if (c != testText[i]) {
printf("Character mismatch at position %d\n" + i);
}
if (iter.current() != c) {
printf("current() isn't working right\n");
}
if (iter.getIndex() != i) {
printf("getIndex() isn't working right [%d should be %d]\n", iter.getIndex(), i);
}
if (c != CharacterIterator::DONE) {
c = iter.previous();
i--;
}
u_fprintf(out, "|");
printUChar(c);
} while (c != CharacterIterator::DONE);
u_fprintf(out, "\n");
delete test2;
}
/* Creating and using text boundaries */
int main( void )
{
cout << "ICU Iterator Sample Program (C++)\n\n";
Test t;
cout << endl;
cout << "Test::TestUCharIter()" << endl;
t.TestUChariter();
cout << "-----" << endl;
cout << "Test::TestStringchariter()" << endl;
t.TestStringiter();
cout << "-----" << endl;
return 0;
UErrorCode status = U_ZERO_ERROR;
out = u_finit(stdout, NULL, NULL);
u_fprintf(out, "ICU Iteration Sample Program (C++)\n\n");
Test t;
u_fprintf(out, "\n");
u_fprintf(out, "Test::TestUCharIter()\n");
t.TestUChariter();
u_fprintf(out, "-----\n");
u_fprintf(out, "Test::TestStringchariter()\n");
t.TestStringiter();
u_fprintf(out, "-----\n");
return 0;
}

View File

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.10"
Name="citer"
ProjectGUID="{247E2681-6C84-408B-B40C-5DB50BC5E18F}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
UsePrecompiledHeader="2"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuucd.lib icuind.lib icuiod.lib"
OutputFile="./Debug/citer.exe"
LinkIncremental="2"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/citer.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="..\..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
RuntimeLibrary="4"
UsePrecompiledHeader="2"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="icuuc.lib icuin.lib icuio.lib"
OutputFile="./Release/citer.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\..\lib"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
<File
RelativePath=".\citer.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2001, International Business Machines
* Copyright (C) 2001 - 2005, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -22,8 +22,8 @@
#include "unicode/utypes.h"
#include "unicode/ustring.h"
void test_current(UChar data[][5], uint32_t size, uint32_t maxLen, uint8_t keys[][32]);
void test_legacy(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[][32]);
extern "C" void test_current(UChar data[][5], uint32_t size, uint32_t maxLen, uint8_t keys[][32]);
extern "C" void test_legacy(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[][32]);
void printZTUChar(const UChar *str) {
while(*str != 0) {

View File

@ -1,12 +1,12 @@
Microsoft Visual Studio Solution File, Format Version 7.00
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "legacy", "legacy.vcproj", "{57F56795-1802-4605-88A0-013AAE9998F6}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
ConfigName.0 = Debug
ConfigName.1 = Release
EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{57F56795-1802-4605-88A0-013AAE9998F6}.Debug.ActiveCfg = Debug|Win32

View File

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2001, International Business Machines
* Copyright (C) 2001 - 2005, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -65,7 +65,7 @@ void closeCollator_current(void) {
}
void test_current(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[][32]) {
extern "C" void test_current(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[][32]) {
uint32_t i = 0;
int32_t keySize = 0;
UVersionInfo uvi;

View File

@ -1,7 +1,7 @@
/*
*******************************************************************************
*
* Copyright (C) 2001-2004, International Business Machines
* Copyright (C) 2001-2005, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
@ -81,7 +81,7 @@ void closeCollator_legacy(void) {
}
void test_legacy(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[4][32]) {
extern "C" void test_legacy(UChar data[][5], uint32_t size, uint32_t maxlen, uint8_t keys[4][32]) {
uint32_t i = 0;
int32_t keySize = 0;