mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 23:10:17 +00:00
validation typos
This commit is contained in:
@@ -613,9 +613,9 @@ TypeError: unorderable types: int() >= str()</samp></pre>
|
||||
<p>In this case, there’s no need to make the code more complicated by adding an explicit coercion. <var>aStr[0]</var> yields an integer; the things you’re comparing to are all constants. Let’s change them from 1-character strings to integers. And while we’re at it, let’s change <var>aStr</var> to <var>aBuf</var>, since it’s not actually a string.
|
||||
<pre class='nd pp'><code> class SJISContextAnalysis(JapaneseContextAnalysis):
|
||||
<del>- def get_order(self, aStr):</del>
|
||||
<del>- if not aStr: return -1, 1
|
||||
<del>- if not aStr: return -1, 1</del>
|
||||
<ins>+ def get_order(self, aBuf):</ins>
|
||||
<ins>+ if not aBuf: return -1, 1
|
||||
<ins>+ if not aBuf: return -1, 1</ins>
|
||||
# find out current char's byte length
|
||||
<del>- if ((aStr[0] >= '\x81') and (aStr[0] <= '\x9F')) or \</del>
|
||||
<del>- ((aBuf[0] >= '\xE0') and (aBuf[0] <= '\xFC')):</del>
|
||||
@@ -626,12 +626,12 @@ TypeError: unorderable types: int() >= str()</samp></pre>
|
||||
charLen = 1
|
||||
|
||||
# return its order if it is hiragana
|
||||
<del>- if len(aStr) > 1:
|
||||
<del>- if len(aStr) > 1:</del>
|
||||
<del>- if (aStr[0] == '\202') and \</del>
|
||||
<del>- (aStr[1] >= '\x9F') and \</del>
|
||||
<del>- (aStr[1] <= '\xF1'):</del>
|
||||
<del>- return ord(aStr[1]) - 0x9F, charLen</del>
|
||||
<ins>+ if len(aBuf) > 1:
|
||||
<ins>+ if len(aBuf) > 1:</ins>
|
||||
<ins>+ if (aBuf[0] == 0x202) and \</ins>
|
||||
<ins>+ (aBuf[1] >= 0x9F) and \</ins>
|
||||
<ins>+ (aBuf[1] <= 0xF1):</ins>
|
||||
@@ -641,9 +641,9 @@ TypeError: unorderable types: int() >= str()</samp></pre>
|
||||
|
||||
class EUCJPContextAnalysis(JapaneseContextAnalysis):
|
||||
<del>- def get_order(self, aStr):</del>
|
||||
<del>- if not aStr: return -1, 1
|
||||
<del>- if not aStr: return -1, 1</del>
|
||||
<ins>+ def get_order(self, aBuf):</ins>
|
||||
<ins>+ if not aBuf: return -1, 1
|
||||
<ins>+ if not aBuf: return -1, 1</ins>
|
||||
# find out current char's byte length
|
||||
<del>- if (aStr[0] == '\x8E') or \</del>
|
||||
<del>- ((aStr[0] >= '\xA1') and (aStr[0] <= '\xFE')):</del>
|
||||
@@ -657,12 +657,12 @@ TypeError: unorderable types: int() >= str()</samp></pre>
|
||||
charLen = 1
|
||||
|
||||
# return its order if it is hiragana
|
||||
<del>- if len(aStr) > 1:
|
||||
<del>- if len(aStr) > 1:</del>
|
||||
<del>- if (aStr[0] == '\xA4') and \</del>
|
||||
<del>- (aStr[1] >= '\xA1') and \</del>
|
||||
<del>- (aStr[1] <= '\xF3'):</del>
|
||||
<del>- return ord(aStr[1]) - 0xA1, charLen</del>
|
||||
<ins>+ if len(aBuf) > 1:
|
||||
<ins>+ if len(aBuf) > 1:</ins>
|
||||
<ins>+ if (aBuf[0] == 0xA4) and \</ins>
|
||||
<ins>+ (aBuf[1] >= 0xA1) and \</ins>
|
||||
<ins>+ (aBuf[1] <= 0xF3):</ins>
|
||||
|
||||
Reference in New Issue
Block a user