Raised This Month: $32 Target: $400
 8% 

Compile CJK chars in *.sp script (UTF8/UCS-2)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ilham92-cc-sakura
Senior Member
Join Date: Oct 2008
Location: /var/www/index.html
Old 06-20-2018 , 21:39   Compile CJK chars in *.sp script (UTF8/UCS-2)
Reply With Quote #1

I wrote some small script to check player name, checking it has CJK character or not.

I make some test run, simple char array
Code:
char CJK = "漢";
However, it appear that SourcePawn wont compile.

so, I make small C# program, as follow:

Code:
\x6f22\x5b57
run forloop to check each chars:
Code:
char CJK = "\x6f22";
...
for(int i = 0; i < 256; i++)
{
	if (PlayerName[i] == '\0')
		break;
	if (PlayerName[i] == CJK)
		found = true;
}
and... it didn't work.
__________________
ilham92-cc-sakura is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 06-20-2018 , 22:06   Re: Compile CJK chars in *.sp script (UTF8/UCS-2)
Reply With Quote #2

They're multi-byte characters, so they'd have to be checked differently. I haven't done it before, but I believe the code below should function fine

Suppose playername had some name value
PHP Code:
char playername[MAX_NAME_LENGTH]; // assume this is filled

if (StrEqual(playername"\xE6\xBC\xA2")) // bytes are '漢'
{
     
// do something


Last edited by headline; 06-20-2018 at 22:06.
headline is offline
ilham92-cc-sakura
Senior Member
Join Date: Oct 2008
Location: /var/www/index.html
Old 06-21-2018 , 04:58   Re: Compile CJK chars in *.sp script (UTF8/UCS-2)
Reply With Quote #3

Quote:
Originally Posted by Headline View Post
PHP Code:
char playername[MAX_NAME_LENGTH]; // assume this is filled

if (StrEqual(playername"\xE6\xBC\xA2")) // bytes are '漢'
{
     
// do something

SourcePawn look character as byte?
it look different what I conver through C#

so I can check Sub String if Player Name contain certain character like this?
Code:
if (StrContains("\xE6\xBC\xA2", playername, false) >= 0)
{
	found = true;
}
Attached Thumbnails
Click image for larger version

Name:	hex.PNG
Views:	108
Size:	2.0 KB
ID:	170210  
__________________
ilham92-cc-sakura is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-21-2018 , 07:35   Re: Compile CJK chars in *.sp script (UTF8/UCS-2)
Reply With Quote #4

Quote:
Originally Posted by ilham92-cc-sakura View Post
SourcePawn look character as byte?
Basically, yes.

Quote:
it look different what I conver through C#
I'm not sure what you mean. Maybe your text editor is using a different encoding than your C# test program.

Quote:
so I can check Sub String if Player Name contain certain character like this?
I don't know if it's safe to tell StrContains to be case-insensitive. But, it should work as long as the encoding you use in your source is the same as what the game uses.

I tested with this code:

PHP Code:
public void OnPluginStart() {
    
char CJK[] = "漢字";
    
char test[] = "感じてない漢字";

    
PrintToServer("%s contains %s? %d"testCJKStrContains(testCJK));

And StrContains did return true: 感じてない漢字 contains 漢字? 15
Fyren is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:42.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode