[sword-cvs] icu-sword/source/samples/break break.cpp,1.1,1.2

sword@www.crosswire.org sword@www.crosswire.org
Tue, 6 Apr 2004 03:10:55 -0700


Update of /cvs/core/icu-sword/source/samples/break
In directory www:/tmp/cvs-serv8911/source/samples/break

Modified Files:
	break.cpp 
Log Message:
ICU 2.8 sync

Index: break.cpp
===================================================================
RCS file: /cvs/core/icu-sword/source/samples/break/break.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- break.cpp	10 Sep 2003 02:42:27 -0000	1.1
+++ break.cpp	6 Apr 2004 10:09:09 -0000	1.2
@@ -7,7 +7,7 @@
 *******************************************************************************
 */
 
-#include <iostream.h>
+#include <stdio.h>
 #include <unicode/brkiter.h>
 #include <stdlib.h>
 
@@ -15,126 +15,129 @@
 
 
 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;
+    char charBuf[1000];
+    s.extract(0, s.length(), charBuf, sizeof(charBuf)-1, 0);   
+    charBuf[sizeof(charBuf)-1] = 0;          
+    printf("%s", charBuf);
 }
 
 
-
 void printTextRange( BreakIterator& iterator, 
-		     int32_t start, int32_t end )
+                    int32_t start, int32_t end )
 {
-  CharacterIterator *strIter = iterator.getText().clone();
-  UnicodeString  s;
-  strIter->getText(s);
+    CharacterIterator *strIter = iterator.getText().clone();
+    UnicodeString  s;
+    strIter->getText(s);
 
-  cout << " " << start << " " << end << " |" ;
-  printUnicodeString(s);
-  cout << "|" << '\n';
-  delete strIter;
+    printf(" %ld %ld\t", (long)start, (long)end);
+    printUnicodeString(UnicodeString(s, 0, start));
+    printf("|");
+    printUnicodeString(UnicodeString(s, start, end-start));
+    printf("|");
+    printUnicodeString(UnicodeString(s, end));
+    puts("");
+    delete strIter;
 }
 
 
 /* Print each element in order: */
 void printEachForward( BreakIterator& boundary)
 {
-  int32_t start = boundary.first();
-  for (int32_t end = boundary.next();
-       end != BreakIterator::DONE;
-       start = end, end = boundary.next())
+    int32_t start = boundary.first();
+    for (int32_t end = boundary.next();
+         end != BreakIterator::DONE;
+         start = end, end = boundary.next())
     {
-      printTextRange( boundary, start, end );
+        printTextRange( boundary, start, end );
     }
 }
 
 /* Print each element in reverse order: */
 void printEachBackward( BreakIterator& boundary)
 {
-  int32_t end = boundary.last();
-  for (int32_t start = boundary.previous();
-       start != BreakIterator::DONE;
-       end = start, start = boundary.previous())
+    int32_t end = boundary.last();
+    for (int32_t start = boundary.previous();
+         start != BreakIterator::DONE;
+         end = start, start = boundary.previous())
     {
-      printTextRange( boundary, start, end );
+        printTextRange( boundary, start, end );
     }
 }
 
 /* Print the first element */
 void printFirst(BreakIterator& boundary)
 {
-  int32_t start = boundary.first();
-  int32_t end = boundary.next();
-  printTextRange( boundary, start, end );
+    int32_t start = boundary.first();
+    int32_t end = boundary.next();
+    printTextRange( boundary, start, end );
 }
 
 /* Print the last element */
 void printLast(BreakIterator& boundary)
 {
-  int32_t end = boundary.last();
-  int32_t start = boundary.previous();
-  printTextRange( boundary, start, end );
+    int32_t end = boundary.last();
+    int32_t start = boundary.previous();
+    printTextRange( boundary, start, end );
 }
 
 /* Print the element at a specified position */
 void printAt(BreakIterator &boundary, int32_t pos )
 {
-  int32_t end = boundary.following(pos);
-  int32_t start = boundary.previous();
-  printTextRange( boundary, start, end );
+    int32_t end = boundary.following(pos);
+    int32_t start = boundary.previous();
+    printTextRange( boundary, start, end );
 }
 
 /* Creating and using text boundaries */
 int main( void )
 {
-  cout << "ICU Break Iterator Sample Program\n\n";
-  cout << "C++ Break Iteration\n\n";
-  BreakIterator* boundary;
-  UnicodeString stringToExamine("Aaa bbb ccc. Ddd eee fff.");
-  cout << "Examining: ";
-  printUnicodeString(stringToExamine);
-  cout << endl;
+    puts("ICU Break Iterator Sample Program\n");
+    puts("C++ Break Iteration\n");
+    BreakIterator* boundary;
+    UnicodeString stringToExamine("Aaa bbb ccc. Ddd eee fff.");
+    printf("Examining: ");
+    printUnicodeString(stringToExamine);
+    puts("");
 
-  //print each sentence in forward and reverse order
-  UErrorCode status = U_ZERO_ERROR;
-  boundary = BreakIterator::createSentenceInstance(
-						   Locale::getUS(), status );
-  if (U_FAILURE(status)) {
-    cout << 
-      "failed to create sentence break iterator.  status = " 
-	 << u_errorName(status);
-    exit(1);
-  }
+    //print each sentence in forward and reverse order
+    UErrorCode status = U_ZERO_ERROR;
+    boundary = BreakIterator::createSentenceInstance(
+        Locale::getUS(), status );
+    if (U_FAILURE(status)) {
+        printf("failed to create sentence break iterator.  status = %s", 
+            u_errorName(status));
+        exit(1);
+    }
 
-  boundary->setText(stringToExamine);
-  cout << "\n Sentence Boundaries... \n";
-  cout << "----- forward: -----------" << '\n';
-  printEachForward(*boundary);
-  cout << "----- backward: ----------" << '\n';
-  printEachBackward(*boundary);
-  delete boundary;
+    boundary->setText(stringToExamine);
+    puts("\n Sentence Boundaries... ");
+    puts("----- forward: -----------");
+    printEachForward(*boundary);
+    puts("----- backward: ----------");
+    printEachBackward(*boundary);
+    delete boundary;
 
-  //print each word in order
-  cout << "\n Word Boundaries... \n";
-  boundary = BreakIterator::createWordInstance(
-					       Locale::getUS(), status);
-  boundary->setText(stringToExamine);
-  cout << "----- forward: -----------" << '\n';
-  printEachForward(*boundary);
-  //print first element
-  cout << "----- first: -------------" << '\n';
-  printFirst(*boundary);
-  //print last element
-  cout << "----- last: --------------" << '\n';
-  printLast(*boundary);
-  //print word at charpos 10
-  cout << "----- at pos 10: ---------" << '\n';
-  printAt(*boundary, 10 );
+    //print each word in order
+    printf("\n Word Boundaries... \n");
+    boundary = BreakIterator::createWordInstance(
+        Locale::getUS(), status);
+    boundary->setText(stringToExamine);
+    puts("----- forward: -----------");
+    printEachForward(*boundary);
+    //print first element
+    puts("----- first: -------------");
+    printFirst(*boundary);
+    //print last element
+    puts("----- last: --------------");
+    printLast(*boundary);
+    //print word at charpos 10
+    puts("----- at pos 10: ---------");
+    printAt(*boundary, 10 );
 
-  delete boundary;
-  cout.flush();
+    delete boundary;
 
-  // Call the C version
-  return c_main();
+    puts("\nEnd C++ Break Iteration");
+
+    // Call the C version
+    return c_main();
 }