Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4068137

Strange word breaking - word break not provided around period at end of string

XMLWordPrintable

    • 1.1.6
    • x86, sparc
    • solaris_2.5.1, windows_nt
    • Verified



        Name: bb33257 Date: 07/29/97


        The following string:

        aa.bb.
        aa"bb"
        aa'bb'

        is broken by the word-break iterator (BreakIterator.
        getWordInstance()) as follows:

        aa.bb
        .
        aa"bb
        "
        aa'bb
        '

        This is probably correct for the apostrophe, but the other two
        should probably break as follows:

        aa
        .
        bb
        .
        aa
        "
        bb
        "
        ======================================================================

        The following app demonstrates the issue that a period at termination
        of scentence is not handled properly. Internal periods are OK. Other
        punctuation is OK (for example a '?' at the end).



        import java.text.BreakIterator;

        class WordBoundary {
               // Creating and using text boundaries

               public static void main(String args[]) {

        String stringToExamine =
        "Mr. Livingston, I presume.";

        // print original text
        System.out.println ("ORIGINAL TEXT:");
        System.out.println(stringToExamine);
        System.out.println("");

                    // print text with separators between words
                    BreakIterator wordBoundary = BreakIterator.getWordInstance();
                    wordBoundary.setText(stringToExamine);
        System.out.println ("WITH WORD BOUNDARIES:");
                    printWithSeparators(wordBoundary, stringToExamine);
               }
         
               // Print a separator '|' at each boundary

               public static void printWithSeparators(BreakIterator boundary, String source) {
                   int start = boundary.first();
                   int end = start;
                   while (end != BreakIterator.DONE) {
        System.out.print(source.substring(start,end));
        System.out.print('|');
                         start = end;
        end = boundary.next();
                   }
        System.out.println();
               }
        }

        gregory.graham@Canada 1997-09-01

              joconnersunw John Oconner (Inactive)
              bcbeck Brian Beck (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: