3.1.5.2.17 GetJamoComposition

This algorithm specifies the strings at the specified index that form a valid Old Hangul character that is composed of a Jamo character sequence.<6>

 COMMENT GetJamoComposition
 COMMENT
 COMMENT  On Entry:  SourceString - Unicode String to test
 COMMENT             CurrentIndex - Index of leading Jamo to start from
 COMMENT             JamoClass    - Class of Jamo to look for
 COMMENT             JamoSortInfo - Information about the current 
 COMMENT                          sequence
 COMMENT  On Exit:   JamoSortInfo - Updated with information about
 COMMENT                            the new sequence
 COMMENT             SourceIndex  - Updated to next character if 
 COMMENT                            Jamo is found
 COMMENT             NewJamoClass - New class to look for next
 COMMENT
 COMMENT NOTE: This function assumes the character at SourceString
 COMMENT       [SourceIndex] is a leading Jamo.
 COMMENT       Ie: IsJamo() returned true
 COMMENT
  
 PROCEDURE GetJamoComposition (IN SourceString : Unicode String,
                            INOUT CurrentIndex : 32 bit integer,
                            IN JamoClass : enumeration,
                            INOUT JamoSortInfo : JamoSortInfoType,
                            OUT NewJamoClass : enumeration)
  
 SET CurrentCharacter to SourceString[CurrentIndex]
  
 // Get the Jamo information for the current character
 SET JamoStateData to CALL GetJamoStateData WITH (CurrentCharacter)
 SET JamoSortInfo to CALL UpdateJamoSortInfo
     WITH (JamoClass, JamoStateData, JamoSortInfo)
  
 // Move on to the next character
 INCREMENT CurrentIndex
  
 WHILE CurrentIndex is less than Length(SourceString)
     SET CurrentCharacter to SourceString[CurrentIndex]
  
     IF CALL IsJamo WITH (CurrentCharacter) is not true THEN
         // The current character is not a Jamo, 
         // Done checking for a Jamo composition
         SET NewJamoClass to "Invalid Jamo Sequence"
         RETURN
     ENDIF
  
     IF CurrentCharacter is equal to 0x1160 THEN
         SET JamoSortInfo.FillerUsed to true
     ENDIF
  
     // Get the Jamo class of it
     IF CALL IsJamoLeading WITH (CurrentCharacter) is true THEN
         SET NewJamoClass to "Leading Jamo Class"
     ELSE IF CALL IsJamoTrailing WITH (CurrentCharacter) is true THEN
         SET NewJamoClass to "Trailing Jamo Class"
     ELSE
         SET NewJamoClass to "Vowel Jamo Class"
     ENDIF
  
     IF JamoClass is not equal to NewJamoClass THEN
         RETURN NewJamoClass
     ENDIF
  
     // Push the current Jamo (SourceString[CurrentIndex])
     // into the state machine to check if it is a valid 
     // old Hangul composition. During the check also
     // update the sortkey result in:
     JamoSortInfo
  
     // Find the new record
     SET JamoStateData to CALL FindNewJamoState
         WITH (CurrentCharacter, JamoStateData)
  
     // A valid old Hangul composition was not found for the current
     // character so return the current Jamo class 
     // (JamoClass and NewJamoClass are identical)
     IF JamoStateData is null THEN
         RETURN NewJamoClass
     ENDIF
  
     // A match has been found, so update our info.
     SET JamoSortInfo to CALL UpdateJamoSortInfo
         WITH (JamoClass, JamoStateData, JamoSortInfo)
  
     // Still in a valid old Hangul composition.  
     //Go check the next character.
     INCREMENT CurrentIndex
  
 ENDWHILE CurrentIndex
  
 SET NewJamoClass to "Invalid Jamo Sequence"
 RETURN NewJamoClass