-
-
Notifications
You must be signed in to change notification settings - Fork 35k
bpo-33578: Add getstate/setstate for CJK codec #6984
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Implement multibyte encoder/decoder state methods |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,6 +51,12 @@ | |
| ; \ | ||
| } | ||
|
|
||
| /* | ||
| * codecs in this file use the first byte of MultibyteCodec_State.c[8] | ||
| * to store a 0 or 1 state value | ||
| */ | ||
| #define CN_STATE_OFFSET 0 | ||
|
|
||
| /* | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the meaning of this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I felt Perhaps even
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I get it:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I were to document how I see Should I add this as a comment next to the union?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me. However And And yes,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added comments next to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good to me, but I'd like @methane to make the final decision about merging this PR. |
||
| * GB2312 codec | ||
| */ | ||
|
|
@@ -329,15 +335,15 @@ DECODER(gb18030) | |
|
|
||
| ENCODER_INIT(hz) | ||
| { | ||
| state->i = 0; | ||
| state->c[CN_STATE_OFFSET] = 0; | ||
| return 0; | ||
| } | ||
|
|
||
| ENCODER_RESET(hz) | ||
| { | ||
| if (state->i != 0) { | ||
| if (state->c[CN_STATE_OFFSET] != 0) { | ||
| WRITEBYTE2('~', '}'); | ||
| state->i = 0; | ||
| state->c[CN_STATE_OFFSET] = 0; | ||
| NEXT_OUT(2); | ||
| } | ||
| return 0; | ||
|
|
@@ -350,10 +356,10 @@ ENCODER(hz) | |
| DBCHAR code; | ||
|
|
||
| if (c < 0x80) { | ||
| if (state->i) { | ||
| if (state->c[CN_STATE_OFFSET]) { | ||
| WRITEBYTE2('~', '}'); | ||
| NEXT_OUT(2); | ||
| state->i = 0; | ||
| state->c[CN_STATE_OFFSET] = 0; | ||
| } | ||
| WRITEBYTE1((unsigned char)c); | ||
| NEXT(1, 1); | ||
|
|
@@ -375,10 +381,10 @@ ENCODER(hz) | |
| if (code & 0x8000) /* MSB set: GBK */ | ||
| return 1; | ||
|
|
||
| if (state->i == 0) { | ||
| if (state->c[CN_STATE_OFFSET] == 0) { | ||
| WRITEBYTE4('~', '{', code >> 8, code & 0xff); | ||
| NEXT(1, 4); | ||
| state->i = 1; | ||
| state->c[CN_STATE_OFFSET] = 1; | ||
| } | ||
| else { | ||
| WRITEBYTE2(code >> 8, code & 0xff); | ||
|
|
@@ -391,13 +397,13 @@ ENCODER(hz) | |
|
|
||
| DECODER_INIT(hz) | ||
| { | ||
| state->i = 0; | ||
| state->c[CN_STATE_OFFSET] = 0; | ||
| return 0; | ||
| } | ||
|
|
||
| DECODER_RESET(hz) | ||
| { | ||
| state->i = 0; | ||
| state->c[CN_STATE_OFFSET] = 0; | ||
| return 0; | ||
| } | ||
|
|
||
|
|
@@ -411,14 +417,14 @@ DECODER(hz) | |
| unsigned char c2 = INBYTE2; | ||
|
|
||
| REQUIRE_INBUF(2); | ||
| if (c2 == '~' && state->i == 0) | ||
| if (c2 == '~' && state->c[CN_STATE_OFFSET] == 0) | ||
| OUTCHAR('~'); | ||
| else if (c2 == '{' && state->i == 0) | ||
| state->i = 1; /* set GB */ | ||
| else if (c2 == '\n' && state->i == 0) | ||
| else if (c2 == '{' && state->c[CN_STATE_OFFSET] == 0) | ||
| state->c[CN_STATE_OFFSET] = 1; /* set GB */ | ||
| else if (c2 == '\n' && state->c[CN_STATE_OFFSET] == 0) | ||
| ; /* line-continuation */ | ||
| else if (c2 == '}' && state->i == 1) | ||
| state->i = 0; /* set ASCII */ | ||
| else if (c2 == '}' && state->c[CN_STATE_OFFSET] == 1) | ||
| state->c[CN_STATE_OFFSET] = 0; /* set ASCII */ | ||
| else | ||
| return 1; | ||
| NEXT_IN(2); | ||
|
|
@@ -428,7 +434,7 @@ DECODER(hz) | |
| if (c & 0x80) | ||
| return 1; | ||
|
|
||
| if (state->i == 0) { /* ASCII mode */ | ||
| if (state->c[CN_STATE_OFFSET] == 0) { /* ASCII mode */ | ||
| OUTCHAR(c); | ||
| NEXT_IN(1); | ||
| } | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.