# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Transliteration to convert Zawgyi text to a more consistent version,
# removing some of the variation in code point order and positioning of
# subscripted consonants and some diacritics.
#
# Possible use: use the conversion rules on Zawgyi to prepare it for comparison
# with other Zawygi text. Note that it's not perfect, but can help with Zawgyi
# text processing.
$consonant = [\u1000-\u1021];
$zmedialra = [\u103b\u107e-\u1084];

\u1009 \u1039 > \u1025 \u1039;
\u1025 \u102e > \u1026 ;
\u102f ([\u102d\u1036]) > $1 \u102f ;
\u1039 ([\u1037\u1094\u1095]) > $1 \u1039 ;
\u103c ([\u102e\u1032]) > $1 \u103c ;
\u1033 \u102d > \u102d \u1033 ;
\u103d \u102d > \u102d \u103d ;
\u1089 > \u103d \u1034 ;

# Kinzi and others
\u1064 \u103a > \u103a \u1064 ;
\u1067 > \u1066 ;
\u1072 > \u1071 ;
\u1074 > \u1073 ;
\u1093 > \u107b ;

# Phase 1. Handle duplicate codes.
::Null;
\u102d+ > \u102d ;
\u102e+ > \u102e ;
\u102f+ > \u102f ;
\u1030+ > \u1030 ;
\u1032+ > \u1032 ;
\u1033+ > \u1033 ;
\u1034+ > \u1034 ;
\u1036+ > \u1036 ;
\u1037+ > \u1037 ;
\u1039+ > \u1039 ;
\u103a+ > \u103a ;
\u103b+ > \u103b ;
\u103c+ > \u103c ;
\u103d+ > \u103d ;
\u103e+ > \u103d ;  # Mix of Unicode and Zawgyi

 # Phase 2. Visually similar results.
::Null;
[\u1037\u1094\u1095]+ > \u1037 ;
\u1005 \u103a > \u1008 ;
\u101d > \u1040 ; # Digit zero
\u104e $ > \u1044 ; # Digit 4 at the end
\u102f \u1088 > \u1088 ;
\u103b \u103a > \u103a \u103b ;
\u103d \u102f > \u1088 ;
\u103d \u1088 > \u1088 ;
\u103b ($consonant) \u103b $ > \u103b $1 ;

# Phase 3. Do not distinguish among various medial ra forms, at least for testing.
::Null;
$zmedialra+ > \u103b;  

# Phase 3.1 Ignore repeated e-vowel
\u1031 \u1031+ > \u1031 ;

# Phase 4. Normalize medial ra plus U sign
::Null;
($zmedialra) ($consonant) \u1036 \u102f > $1 $2 \u1033 \u1036;

# Phase 5. Handle variants
::Null;
\u1033 > \u102f ;

# Phase 6: More visually similar
::Null;
\u1036 \u102f > \u102f \u1036;
\u1037 \u1039 \u1037 > \u1037 \u1039 ;
\u106b > \u100a;

# Phase N. Remove spaces.
::Null;
[:WSpace:]+ ([\u1000-\u109f]) > | $1 ;

# Ignore ZWSP at start and end of string
^ \u200b+ > ;
\u200b+ $ > ;
