diff options
| author | Po Lu | 2023-08-04 14:29:55 +0800 |
|---|---|---|
| committer | Po Lu | 2023-08-04 14:29:55 +0800 |
| commit | bfbdf4eb892935536fc665d6cc986fd669364263 (patch) | |
| tree | f82fdd0cafacdd9133356f5c264514a726018a18 /src/androidvfs.c | |
| parent | 709195fea6a082e3512c14fe16c4f9ea2f99824c (diff) | |
| download | emacs-bfbdf4eb892935536fc665d6cc986fd669364263.tar.gz emacs-bfbdf4eb892935536fc665d6cc986fd669364263.zip | |
Optimize creation of multibyte menu items on Android
* src/androidvfs.c (android_verify_jni_string): Move to
android.c.
* src/android.c (android_verify_jni_string): New function.
(android_build_string): Forgo encoding menu text if TEXT is a
multibyte string that's also a valid JNI string.
* src/android.h: Update prototypes.
Diffstat (limited to 'src/androidvfs.c')
| -rw-r--r-- | src/androidvfs.c | 63 |
1 files changed, 0 insertions, 63 deletions
diff --git a/src/androidvfs.c b/src/androidvfs.c index 2b467bc444f..0d99116c75c 100644 --- a/src/androidvfs.c +++ b/src/androidvfs.c | |||
| @@ -3299,9 +3299,6 @@ static struct android_saf_root_vdir *all_saf_root_vdirs; | |||
| 3299 | static struct android_vnode *android_saf_tree_from_name (char *, const char *, | 3299 | static struct android_vnode *android_saf_tree_from_name (char *, const char *, |
| 3300 | const char *); | 3300 | const char *); |
| 3301 | 3301 | ||
| 3302 | /* Forward declaration. */ | ||
| 3303 | static int android_verify_jni_string (const char *); | ||
| 3304 | |||
| 3305 | /* Ascertain and return whether or not AUTHORITY designates a content | 3302 | /* Ascertain and return whether or not AUTHORITY designates a content |
| 3306 | provider offering at least one directory tree accessible to | 3303 | provider offering at least one directory tree accessible to |
| 3307 | Emacs. */ | 3304 | Emacs. */ |
| @@ -4437,66 +4434,6 @@ static struct android_vops saf_new_vfs_ops; | |||
| 4437 | /* Chain of all open SAF directory streams. */ | 4434 | /* Chain of all open SAF directory streams. */ |
| 4438 | static struct android_saf_tree_vdir *all_saf_tree_vdirs; | 4435 | static struct android_saf_tree_vdir *all_saf_tree_vdirs; |
| 4439 | 4436 | ||
| 4440 | /* Verify that the specified NULL-terminated STRING is a valid JNI | ||
| 4441 | ``UTF-8'' string. Return 0 if so, 1 otherwise. | ||
| 4442 | |||
| 4443 | The native coding system used by the JVM to store strings derives | ||
| 4444 | from UTF-8, but deviates from it in two aspects in an attempt to | ||
| 4445 | better represent the UCS-16 based Java String format, and to let | ||
| 4446 | strings contain NULL characters while remaining valid C strings: | ||
| 4447 | NULL bytes are encoded as two-byte sequences, and Unicode surrogate | ||
| 4448 | pairs encoded as two-byte sequences are prefered to four-byte | ||
| 4449 | sequences when encoding characters above the BMP. */ | ||
| 4450 | |||
| 4451 | static int | ||
| 4452 | android_verify_jni_string (const char *name) | ||
| 4453 | { | ||
| 4454 | const unsigned char *chars; | ||
| 4455 | |||
| 4456 | chars = (unsigned char *) name; | ||
| 4457 | while (*chars) | ||
| 4458 | { | ||
| 4459 | /* Switch on the high 4 bits. */ | ||
| 4460 | |||
| 4461 | switch (*chars++ >> 4) | ||
| 4462 | { | ||
| 4463 | case 0 ... 7: | ||
| 4464 | /* The 8th bit is clean, so this is a regular C | ||
| 4465 | character. */ | ||
| 4466 | break; | ||
| 4467 | |||
| 4468 | case 8 ... 0xb: | ||
| 4469 | /* Invalid starting byte! */ | ||
| 4470 | return 1; | ||
| 4471 | |||
| 4472 | case 0xf: | ||
| 4473 | /* The start of a four byte sequence. These aren't allowed | ||
| 4474 | in Java. */ | ||
| 4475 | return 1; | ||
| 4476 | |||
| 4477 | case 0xe: | ||
| 4478 | /* The start of a three byte sequence. Verify that its | ||
| 4479 | continued. */ | ||
| 4480 | |||
| 4481 | if ((*chars++ & 0xc0) != 0x80) | ||
| 4482 | return 1; | ||
| 4483 | |||
| 4484 | FALLTHROUGH; | ||
| 4485 | |||
| 4486 | case 0xc ... 0xd: | ||
| 4487 | /* The start of a two byte sequence. Verify that the | ||
| 4488 | next byte exists and has its high bit set. */ | ||
| 4489 | |||
| 4490 | if ((*chars++ & 0xc0) != 0x80) | ||
| 4491 | return 1; | ||
| 4492 | |||
| 4493 | break; | ||
| 4494 | } | ||
| 4495 | } | ||
| 4496 | |||
| 4497 | return 0; | ||
| 4498 | } | ||
| 4499 | |||
| 4500 | /* Find the document ID of the file within TREE_URI designated by | 4437 | /* Find the document ID of the file within TREE_URI designated by |
| 4501 | NAME. | 4438 | NAME. |
| 4502 | 4439 | ||