Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Added 'preg_match' script command to match regular expressions.
The command is only available if the PCRE library is installed. Updated indefinite articles in Global_Functions with regex. (credits: Kaivosukeltaja/php-indefinite-article/863f1d5) Signed-off-by: Euphy <euphy.raliel@rathena.org>
- Loading branch information
Showing
with
105 additions
and 6 deletions.
- +12 −1 doc/script_commands.txt
- +56 −5 npc/other/Global_Functions.txt
- +37 −0 src/map/script.c
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @@ -3,7 +3,7 @@ | ||
| //===== By: ================================================== | ||
| //= Lupus, kobra_k88 | ||
| //===== Current Version: ===================================== | ||
| //= 2.23 | ||
| //===== Compatible With: ===================================== | ||
| //= rAthena Project | ||
| //===== Description: ========================================= | ||
| @@ -45,6 +45,7 @@ | ||
| //= Standardized descriptions, updated 'F_GetArmorType'. | ||
| //= 2.21 Added format string to "F_InsertPlural" and more checks to "F_GetPlural". [Euphy] | ||
| //= 2.22 Further improvements to "F_GetPlural". [Euphy] | ||
| //= 2.23 Completed article function and added "F_GetArticle". [Euphy] | ||
| //============================================================ | ||
|
|
||
| ////////////////////////////////////////////////////////////////////////////////// | ||
| @@ -458,14 +459,64 @@ function script F_InsertPlural { | ||
|
|
||
|
|
||
| ////////////////////////////////////////////////////////////////////////////////// | ||
| // Returns 'a' or 'an' based on a word. | ||
| // -- callfunc "F_GetArticle","<noun>"; | ||
| // Examples: | ||
| // callfunc("F_GetArticle","Apple") // returns "an" | ||
| // callfunc("F_GetArticle","dog") // returns "a" | ||
| // | ||
| // Returns 'a' or 'an' based on a word, followed by the word. | ||
| // -- callfunc "F_InsertArticle","<word>"{,<0:lowercase a/1:uppercase A>} | ||
| // Examples: | ||
| // callfunc("F_InsertArticle","Apple") // returns "an Apple" | ||
| // callfunc("F_InsertArticle","dog",1) // returns "A dog" | ||
| ////////////////////////////////////////////////////////////////////////////////// | ||
| function script F_GetArticle { | ||
| set .@str$, strtolower(getarg(0)); | ||
|
|
||
| // not a word | ||
| if (!charisalpha(.@str$,0)) | ||
| return "a"; | ||
|
|
||
| // 1-letter words | ||
| if (getstrlen(.@str$) == 1) { | ||
| if (strpos("aefhilmnorsx",.@str$) > -1) | ||
| return "an"; | ||
| else | ||
| return "a"; | ||
| } | ||
|
|
||
| // special cases | ||
| if (preg_match("(euler|hour(?!i)|heir|honest|hono)",.@str$)) | ||
This comment has been minimized.
This comment has been minimized.
euphyy
Author
Contributor
|
||
| return "an"; | ||
|
|
||
| // consonants | ||
| if (preg_match("^[^aeiouy]",.@str$)) | ||
| return "a"; | ||
|
|
||
| // special vowel forms | ||
| if (preg_match("^e[uw]",.@str$) || preg_match("^onc?e\b",.@str$) || preg_match("^uni([^nmd]|mo)",.@str$) || preg_match("^u[bcfhjkqrst][aeiou]",.@str$)) | ||
| return "a"; | ||
| if (preg_match("^ut[th]",.@str$)) | ||
| return "an"; | ||
|
|
||
| // special capitals (rare) | ||
| //if (preg_match("^U[NK][AIEO]?",getarg(0))) | ||
| // return "a"; | ||
|
|
||
| // vowels | ||
| if (preg_match("^[aeiou]",.@str$)) | ||
| return "an"; | ||
|
|
||
| // y... (rare) | ||
| //if (preg_match("^(y(b[lor]|cl[ea]|fere|gg|p[ios]|rou|tt))",.@str$)) | ||
| // return "an"; | ||
|
|
||
| return "a"; | ||
| } | ||
| function script F_InsertArticle { | ||
| set .@article$, callfunc("F_GetArticle",getarg(0)); | ||
| return sprintf("%s %s", ((getarg(1,0)) ? replacestr(.@article$,"a","A") : .@article$), getarg(0)); | ||
| } | ||
|
|
||
|
|
||
| @@ -494,7 +545,7 @@ function script F_InsertComma { | ||
| function script F_GetNumSuffix { | ||
| set .@n, getarg(0); | ||
| set .@mod, .@n % 10; | ||
| if (.@mod == 1 && .@n != 11) return .@n+"st"; | ||
| else if (.@mod == 2 && .@n != 12) return .@n+"nd"; | ||
| else if (.@mod == 3 && .@n != 13) return .@n+"rd"; | ||
| else return .@n+"th"; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How about server that running in windows?
Currently, map serv will warn a syntax error when running this script...