Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codepoint under win10 64 bit #170

Open
LukyGuyLucky opened this issue Jan 3, 2025 · 2 comments
Open

Codepoint under win10 64 bit #170

LukyGuyLucky opened this issue Jan 3, 2025 · 2 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@LukyGuyLucky
Copy link

LukyGuyLucky commented Jan 3, 2025

With below code snippet under win10 64 bit,source code in UTF8 no BOM & UTF8-BOM resulted in different display.
NappGUI has been built with MS Visual Studio 2022,64bit ,Release build.

  1. while(cp!='\0') will result an infinite loop;while(cp!=-1) works.Don't know why
  2. source code in UTF8 with BOM,console code page 936
    Great thing: escape (\n) after a Chinese character works properly
    issue: the while loop been interrupted,don't know why
    ---under code page 65001,all none ascii characters displayed improperly.
活动代码页: 936

E:\nappgui\build\Release\bin>con01
你好C+NappGUI元旦快乐!   //<--- escape works
Happy New Year!
Orignal string : Ramón tiene un camión
Γει? σου Κ?σμε!????
cp=R
Item index #0   item value 97
Item index #1   item value 109
found !!
Item index #2   item value -1
[20:09:40] [OK] Heap Memory Statistics
[20:09:40] ===========================
[20:09:40] Total a/dellocations: 40, 40
[20:09:40] Total bytes a/dellocated: 8939, 8939
[20:09:40] Max bytes allocated: 8811
[20:09:40] Effective reallocations: (0/2)
[20:09:40] Real allocations: 1 pages of 65536 bytes
[20:09:40] ============================
[20:09:40] Config: Release


  1. source code int UTF8,cosole code page 65001
    issue: escape (\n) after Chinese character doesn't work.
    Greate:while loop works as expected.
Active code page: 65001

E:\nappgui\build\Release\bin>con01
你好C+NappGUI元旦快乐!\nHappy New Year!
Orignal string : Ramón tiene un camión
Γειά σου Κόσμε!👋🌎
cp=R
Item index #0   item value 97
Item index #1   item value 109
found !!
Item index #2   item value 243
Item index #3   item value 110
Item index #4   item value 32
Item index #5   item value 116
Item index #6   item value 105
Item index #7   item value 101
Item index #8   item value 110
Item index #9   item value 101
Item index #10  item value 32
Item index #11  item value 117
Item index #12  item value 110
Item index #13  item value 32
Item index #14  item value 99
Item index #15  item value 97
Item index #16  item value 109
found !!
Item index #17  item value 105
Item index #18  item value 243
Item index #19  item value 110
Item index #20  item value 10
Item index #21  item value 915
Item index #22  item value 949
Item index #23  item value 953
Item index #24  item value 940
Item index #25  item value 32
Item index #26  item value 963
Item index #27  item value 959
Item index #28  item value 965
Item index #29  item value 32
Item index #30  item value 922
Item index #31  item value 972
Item index #32  item value 963
Item index #33  item value 956
Item index #34  item value 949
Item index #35  item value 33
Item index #36  item value 128075
Item index #37  item value 127758
Item index #38  item value 0
Item index #39  item value 0
Item index #40  item value 0
Item index #41  item value 0
Item index #42  item value 0
Item index #43  item value -1
[20:24:05] [OK] Heap Memory Statistics
[20:24:05] ===========================
[20:24:05] Total a/dellocations: 40, 40
[20:24:05] Total bytes a/dellocated: 8939, 8939
[20:24:05] Max bytes allocated: 8811
[20:24:05] Effective reallocations: (0/2)
[20:24:05] Real allocations: 1 pages of 65536 bytes
[20:24:05] ============================
[20:24:05] Config: Release

main.c

/* NAppGUI Console Application */
    
#include "core/coreall.h"

void test(void);
int main(int argc, char *argv[])
{
    unref(argc);
    unref(argv);
    core_start();
    bstd_printf("你好C+NappGUI元旦快乐!\nHappy New Year!\n");  //<----escape doesn't work
	
    test();
    
    core_finish();
    return 0;
}

void test(void)
{
	int32_t i=0;
	const char_t mystr[]="Ramón tiene un camión\nΓειά σου Κόσμε!👋🌎";
        bstd_printf("Orignal string : %s\n",mystr);
	const char_t *it=mystr;
        uint32_t cp=unicode_to_u32(it,ekUTF8);
    
        bstd_printf("cp=%c\n",cp);
    
	while(cp!=-1)
	{
		if(unicode_to_u32(it,ekUTF8)=='m')
		{
			bstd_printf("found !!\n");
		}
		it=unicode_next(it,ekUTF8);
		cp=unicode_to_u32(it,ekUTF8);
		bstd_printf("Item index #%d\titem value %d\n",i++,cp);
	}
    
}

@frang75 frang75 self-assigned this Jan 7, 2025
@frang75 frang75 added the help wanted Extra attention is needed label Jan 7, 2025
@frang75
Copy link
Owner

frang75 commented Jan 7, 2025

Hi @LukyGuyLucky!

Its not a NAppGUI problem, is how Windows cmd/terminal show UTF-8 characters. You have to configure the terminal to show them:
https://stackoverflow.com/questions/57131654/using-utf-8-encoding-chcp-65001-in-command-prompt-windows-powershell-window
Also you have to ensure use the UTF-8 without signature encoding to save your source file:
unicode

If you test you code in a Linux terminal works fine:
unicode_working_linux

Also you have a bug in your test function. while(cp!=-1) is really while(cp!=0). '\0' is the string end null character (not -1).

@frang75
Copy link
Owner

frang75 commented Jan 7, 2025

你好C+NappGUI元旦快乐!
Happy New Year!
Orignal string : Ramón tiene un camión
Γειά σου Κόσμε!👋🌎
cp=R
Item index #0	item value 97
Item index #1	item value 109
found !!
Item index #2	item value 243
Item index #3	item value 110
Item index #4	item value 32
Item index #5	item value 116
Item index #6	item value 105
Item index #7	item value 101
Item index #8	item value 110
Item index #9	item value 101
Item index #10	item value 32
Item index #11	item value 117
Item index #12	item value 110
Item index #13	item value 32
Item index #14	item value 99
Item index #15	item value 97
Item index #16	item value 109
found !!
Item index #17	item value 105
Item index #18	item value 243
Item index #19	item value 110
Item index #20	item value 10
Item index #21	item value 915
Item index #22	item value 949
Item index #23	item value 953
Item index #24	item value 940
Item index #25	item value 32
Item index #26	item value 963
Item index #27	item value 959
Item index #28	item value 965
Item index #29	item value 32
Item index #30	item value 922
Item index #31	item value 972
Item index #32	item value 963
Item index #33	item value 956
Item index #34	item value 949
Item index #35	item value 33
Item index #36	item value 128075
Item index #37	item value 127758
Item index #38	item value 0
[21:23:10] [OK] Heap Memory Statistics
[21:23:10] ===========================
[21:23:10] Total a/dellocations: 40, 40
[21:23:10] Total bytes a/dellocated: 8939, 8939
[21:23:10] Max bytes allocated: 8811
[21:23:10] Effective reallocations: (0/2)
[21:23:10] Real allocations: 1 pages of 65536 bytes
[21:23:10] ============================
[21:23:10] Config: Debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants