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

Importing Unicode replacement json files #167

Open
mablue opened this issue Feb 16, 2024 · 3 comments
Open

Importing Unicode replacement json files #167

mablue opened this issue Feb 16, 2024 · 3 comments

Comments

@mablue
Copy link

mablue commented Feb 16, 2024

db.json

import emoji

# Get all emoji names
all = emoji.EMOJI_DATA
i = 1
rlist = []
for pattern in all:
    i+=1
    replacement = all[pattern]['fa'].replace(":"," ").replace('_',' ')
    name = f"{pattern} {replacement}"
    db = {"id":i+1708092241186,"name":name,"pattern":pattern,"replacement":replacement,"order":i}
    rlist.append(db)
print(rlist)

full_content = [
    {
        "group": {
            "id": 1,
            "name": "گروه بندی پیش فرض"
        },
        "list": rlist
    }
]

with open('db.json','w',encoding="utf8") as file:
    file.write(str(full_content).replace("'",'"'))

Error

kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 10945: Invalid escaped char 'U' at path: $[0].list[90].name
JSON input: ....."id": 1708092241278, "name": "🏴\U000e0067\U000e0062\U000e00.....
	at zh.m.l(OnEnterRule.java:32)
	at zh.m.m(OnEnterRule.java:35)
	at ug.a.n(AbstractJsonLexer.kt:52)
	at ug.a.o(AbstractJsonLexer.kt:13)
	at ug.d0.e(StringJsonLexer.kt:125)
	at ug.a.j(AbstractJsonLexer.kt:12)
	at ug.a.k(AbstractJsonLexer.kt:44)
	at ug.a.l(AbstractJsonLexer.kt:1)
	at ug.a0.I(StreamingJsonDecoder.kt:9)
	at android.support.v4.media.a.C(MediaBrowserCompat.java:6)
	at ia.b$a.d(ReplaceRule.kt:97)
	at ug.a0.c0(StreamingJsonDecoder.kt:71)
	at android.support.v4.media.a.e0(MediaBrowserCompat.java:11)
	at ug.a0.e0(StreamingJsonDecoder.kt:46)
	at sg.o.k(CollectionSerializers.kt:8)
	at sg.a.j(CollectionSerializers.kt:38)
	at sg.a.d(CollectionSerializers.kt:6)
	at ug.a0.c0(StreamingJsonDecoder.kt:71)
	at android.support.v4.media.a.e0(MediaBrowserCompat.java:11)
	at ug.a0.e0(StreamingJsonDecoder.kt:46)
	at ia.a$a.d(GroupWithReplaceRule.kt:38)
	at ug.a0.c0(StreamingJsonDecoder.kt:71)
	at android.support.v4.media.a.e0(MediaBrowserCompat.java:11)
	at ug.a0.e0(StreamingJsonDecoder.kt:46)
	at sg.o.k(CollectionSerializers.kt:8)
	at sg.a.j(CollectionSerializers.kt:38)
	at sg.a.d(CollectionSerializers.kt:6)
	at ug.a0.c0(StreamingJsonDecoder.kt:71)
	at tg.a.a(Json.kt:31)
	at x9.z$c.invoke(ReplaceRuleImportBottomSheet.kt:45)
	at q9.g0.invokeSuspend(ConfigImportBottomSheet.kt:86)
	at ff.a.resumeWith(ContinuationImpl.kt:9)
	at eg.p0.run(DispatchedTask.kt:111)
	at a2.l1.U(AndroidUiDispatcher.android.kt:7)
	at a2.l1$c.run(AndroidUiDispatcher.android.kt:3)
	at android.os.Handler.handleCallback(Handler.java:958)
	at android.os.Handler.dispatchMessage(Handler.java:99)
	at android.os.Looper.loopOnce(Looper.java:205)
	at android.os.Looper.loop(Looper.java:294)
	at android.app.ActivityThread.main(ActivityThread.java:8244)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

@mablue
Copy link
Author

mablue commented Feb 16, 2024

\{[^\{]+\\U[^\{]+\},

I removed buggy emojies but its not true way

db.json

@mablue
Copy link
Author

mablue commented Feb 23, 2024

f.json
I fixed the problem with this code but it generates english and I think it have not all advanced emojies

import unicodedata

i = 1
rlist = []

for codepoint in range(0x110000):
    i+=1
    replacement = chr(codepoint)
    if unicodedata.category(replacement) in ['So','Sm']:
        print(replacement, end=' ')
        pattern = unicodedata.name(replacement)
        name = f"{replacement} {pattern}"
        db = {
            "id":i,
            "name":name,
            "pattern":pattern,
            "replacement":replacement,
            "order":i
        }
        rlist.append(db)
        
full_content = [
    {
        "group": {
            "id": 1,
            "name": "Default group"
        },
        "list": rlist
    }
]

with open('f.json','w',encoding="utf8") as file:
    file.write(str(full_content).replace("'",'"'))

@mablue
Copy link
Author

mablue commented Mar 4, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant