20 namespace Deveel.Data.Text {
28 private string vowels =
"AEIOU";
29 private string frontv =
"EIY";
30 private string varson =
"CSPTG";
31 private int maxCodeLen = 4;
34 #region Private Methods
39 private bool RegionMatch(StringBuilder sb,
int index, String test) {
42 (index + test.Length - 1) < sb.Length) {
43 string substring = sb.ToString(index, test.Length);
44 matches = substring.Equals(test);
49 private bool IsVowel(StringBuilder sb,
int index) {
50 return (this.vowels.IndexOf(sb[index]) >= 0);
55 if( index > 0 && index < sb.Length) {
56 matches = sb[index - 1] == c;
61 private bool IsNextChar(StringBuilder sb,
int index,
char c) {
63 if (index >= 0 && index < sb.Length - 1) {
64 matches = sb[index + 1] == c;
70 #region Public Methods
72 if (
string.IsNullOrEmpty(s))
79 char[] inwd = s.ToUpper().ToCharArray() ;
81 StringBuilder local =
new StringBuilder(40);
82 StringBuilder code =
new StringBuilder(10) ;
89 local.Append(inwd, 1, inwd.Length - 1);
96 local.Append(inwd, 1, inwd.Length - 1);
102 if (inwd[1] ==
'R') {
103 local.Append(inwd, 1, inwd.Length - 1);
106 if (inwd[1] ==
'H') {
107 local.Append(inwd, 1, inwd.Length - 1);
122 int wdsz = local.Length;
125 while ((code.Length <
this.maxCodeLen) &&
127 char symb = local[n];
129 if ((symb !=
'C') && (IsPreviousChar( local, n, symb )) ) {
133 case 'A' :
case 'E' :
case 'I' :
case 'O' :
case 'U' :
139 if (IsPreviousChar(local, n,
'M') &&
140 IsLastChar(wdsz, n) ) {
147 if (IsPreviousChar(local, n,
'S') &&
148 !IsLastChar(wdsz, n) &&
149 (this.frontv.IndexOf(local[n + 1]) >= 0)) {
152 if (RegionMatch(local, n,
"CIA")) {
156 if (!IsLastChar(wdsz, n) &&
157 (this.frontv.IndexOf(local[n + 1]) >= 0)) {
161 if (IsPreviousChar(local, n,
'S') &&
162 IsNextChar(local, n,
'H') ) {
166 if (IsNextChar(local, n,
'H')) {
179 if (!IsLastChar(wdsz, n + 1) &&
180 IsNextChar(local, n,
'G') &&
181 (this.frontv.IndexOf(local[n + 2]) >= 0)) {
182 code.Append(
'J'); n += 2 ;
188 if (IsLastChar(wdsz, n + 1) &&
189 IsNextChar(local, n,
'H')) {
192 if (!IsLastChar(wdsz, n + 1) &&
193 IsNextChar(local,n,
'H') &&
194 !IsVowel(local,n+2)) {
198 (RegionMatch(local, n,
"GN") ||
199 RegionMatch(local, n,
"GNED") ) ) {
203 if (IsPreviousChar(local, n,
'G')) {
208 if (!IsLastChar(wdsz, n) &&
209 (this.frontv.IndexOf(local[n + 1]) >= 0) &&
217 if (IsLastChar(wdsz, n)) {
221 (this.varson.IndexOf(local[n - 1]) >= 0)) {
224 if (IsVowel(local,n+1)) {
238 if (!IsPreviousChar(local, n,
'C')) {
246 if (IsNextChar(local,n,
'H')) {
257 if (RegionMatch(local,n,
"SH") ||
258 RegionMatch(local,n,
"SIO") ||
259 RegionMatch(local,n,
"SIA")) {
266 if (RegionMatch(local,n,
"TIA") ||
267 RegionMatch(local,n,
"TIO")) {
271 if (RegionMatch(local,n,
"TCH")) {
276 if (RegionMatch(local,n,
"TH")) {
285 case 'W' :
case 'Y' :
286 if (!IsLastChar(wdsz,n) &&
287 IsVowel(local,n+1)) {
301 if (code.Length >
this.maxCodeLen) {
302 code.Length = maxCodeLen;
305 return code.ToString();
bool RegionMatch(StringBuilder sb, int index, String test)
bool IsVowel(StringBuilder sb, int index)
bool IsPreviousChar(StringBuilder sb, int index, char c)
bool IsNextChar(StringBuilder sb, int index, char c)
bool IsLastChar(int wdsz, int n)