Skip to main content

GetCodepointDecompositionHangul

Short summary

This function creates a the decomposition of a given precomposed hangul syllable code point. To find out how it works, check out the unicode standard, section 3.12. If no decomposition is possible, the method returns FALSE. This method finds only canonical decompositions used for NFD/NFC normalization. It does not provide compatible decompositions used for NFKC/NFKD forms.

Attention: The returned normalizedCodePoints is a dynamically created pointer! It needs to be deleted after usage.

  • Return type: BOOL

Parameters

NameTypeCommentKind
codepointPOINTER TO UnicodeCodePointcodepoint that should be decomposedinput
newCodepointsPOINTER TO UnicodeCodePointshould be at least the size of 4 codepointsinput
numberOfCodepointsUDINTamount of codepoints that replaces the given codepointoutput

Code

Declaration

FUNCTION INTERNAL GetCodepointDecompositionHangul :BOOL
VAR_INPUT
(* codepoint that should be decomposed *)
codepoint :POINTER TO UnicodeCodePoint;
(* should be at least the size of 4 codepoints *)
newCodepoints :POINTER TO UnicodeCodePoint;
END_VAR
VAR_OUTPUT
(* amount of codepoints that replaces the given codepoint *)
numberOfCodepoints :UDINT;
END_VAR
VAR
syllableIndex :UnicodeCodePoint;
L, V, T :UnicodeCodePoint;
END_VAR

Implementation

GetCodepointDecompositionHangul := FALSE;
syllableIndex := codepoint^ - HangulCommonConstants.S_BASE;
RETURN((syllableIndex < 0) OR_ELSE (syllableIndex >= HangulCommonConstants.S_COUNT));

L := HangulCommonConstants.L_BASE + (syllableIndex / HangulCommonConstants.N_COUNT);
V := HangulCommonConstants.V_BASE + ((syllableIndex MOD HangulCommonConstants.N_COUNT) / HangulCommonConstants.T_COUNT);
T := HangulCommonConstants.T_BASE + (syllableIndex MOD HangulCommonConstants.T_COUNT);

IF ( T = HangulCommonConstants.T_BASE ) THEN
numberOfCodepoints := 2;
newCodepoints[0] := L;
newCodepoints[1] := V;
ELSE
numberOfCodepoints := 3;
newCodepoints[0] := L;
newCodepoints[1] := V;
newCodepoints[2] := T;
END_IF

GetCodepointDecompositionHangul := TRUE;