Merge lp:~lielft-deactivatedaccount/rtlplo0x/first-char-bugfix into lp:rtlplo0x

Proposed by Liel Fridman on 2010-12-05
Status: Merged
Merged at revision: 2
Proposed branch: lp:~lielft-deactivatedaccount/rtlplo0x/first-char-bugfix
Merge into: lp:rtlplo0x
Diff against target: 86 lines (+75/-0) (has conflicts)
1 file modified
RTLplo0x.py (+75/-0)
Text conflict in RTLplo0x.py
To merge this branch: bzr merge lp:~lielft-deactivatedaccount/rtlplo0x/first-char-bugfix
Reviewer Review Type Date Requested Status
Ddorda 2010-12-05 Approve on 2010-12-05
Review via email: mp+42772@code.launchpad.net
To post a comment you must log in.
Ddorda (ddorda) wrote :

This is a patch and not a standing commit. please publish a full code for merge or upload the patch to the right bug report. Thanks!

review: Needs Fixing
Ddorda (ddorda) wrote :

My bad. works excellent! stupid LP.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'RTLplo0x.py'
2--- RTLplo0x.py 2010-12-05 10:04:40 +0000
3+++ RTLplo0x.py 2010-12-05 10:14:52 +0000
4@@ -1,3 +1,4 @@
5+<<<<<<< TREE
6 #!/usr/bin/python
7 # -*- coding: utf-8 -*-
8 """
9@@ -70,3 +71,77 @@
10 return xchat.EAT_XCHAT # disable regular Xchat function
11
12 xchat.hook_command("", check_chars)
13+=======
14+#!/usr/bin/python
15+# -*- coding: utf-8 -*-
16+"""
17+ Wrote by: Ddorda <Ddorda Strüdle(at) ubuntu.com> - <http://ddorda.useopensource.net> and cleaned by MKsoft
18+
19+ This program (As known as "RTLplo0x") is free software: you can redistribute it and/or modify
20+ it under the terms of the GNU General Public License as published by
21+ the Free Software Foundation, either version 3 of the License, or
22+ (at your option) any later version.
23+
24+ This program is distributed in the hope that it will be useful,
25+ but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ GNU General Public License for more details.
28+
29+ You should have received a copy of the GNU General Public License
30+ along with this program. If not, see <http://www.gnu.org/licenses/>.
31+
32+
33+ -------------------------
34+
35+README:
36+ - This is an Xchat2 plugin. to install it you should copy this file into ~/.xchat2/ directory.
37+ - RTLplo0x supports any known RTL/LTR language, even though it was written for Hebrew/English in the beggining.
38+"""
39+
40+import xchat
41+from unicodedata import lookup, bidirectional
42+
43+__module_name__ = "RTLplo0x"
44+__module_version__ = "1.0"
45+__module_description__ = "RTL my /MSG Plo0x!"
46+
47+# some constants for readability
48+RLM = lookup('RIGHT-TO-LEFT MARK')
49+LRM = lookup('LEFT-TO-RIGHT MARK')
50+
51+# we take into account 'L' as strong left, and 'R' and 'AL' as strong
52+# right. If you want other types, add them here. For more info see:
53+# http://unicode.org/reports/tr9/#Bidirectional_Character_Types
54+STRONG_LEFT = ('L', )
55+STRONG_RIGHT = ('R', 'AL')
56+
57+def check_chars(word, word_eol, userdata):
58+ """Count the strong right and left bidirectional char types. Based on the
59+ Unicode algorithm. Ignores if it starts with RLM or LRM (allowing to
60+ override behavior). Assumes that text is utf-8 encoded
61+
62+
63+ """
64+
65+ unistr = word_eol[0].decode('utf-8')
66+ if not unistr.startswith( (RLM, LRM, '!', '@', '+', '-', '.') ):
67+ # holds the count of char types. Key is char type, value is count
68+ char_types = {}
69+ for unichar in unistr:
70+ char_type = bidirectional(unichar)
71+ char_types[char_type] = char_types.get(char_type, 0) + 1
72+
73+ total_left = sum( char_types.get(x, 0) for x in STRONG_LEFT )
74+ total_right = sum( char_types.get(x, 0) for x in STRONG_RIGHT )
75+
76+ if len(word) > 0 and word[0].endswith( ":" ): total_left = ( total_left - len( word[0] ) + 1 ) # total_left = itself without "nick:"
77+
78+ if total_right > total_left:
79+ unistr = RLM + unistr
80+ else:
81+ unistr = LRM + unistr
82+ xchat.command("say " + unistr.encode('utf-8')) # print fixed text
83+ return xchat.EAT_XCHAT # disable regular Xchat function
84+
85+xchat.hook_command("", check_chars)
86+>>>>>>> MERGE-SOURCE

Subscribers

People subscribed via source and target branches

to all changes: