Repository :
http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : master
---------------------------------------------------------------
commit a2f95b5e55ad1e4c060af9e2e3e25999a86e1bbe
Author: Mike FABIAN <mfabian(a)redhat.com>
Date: Tue Dec 15 16:32:40 2015 +0100
Add an is_ascii() utility function
---------------------------------------------------------------
ibus-typing-booster/engine/itb_util.py | 29 ++++++++++++++++++++++++++++-
1 files changed, 28 insertions(+), 1 deletions(-)
diff --git a/ibus-typing-booster/engine/itb_util.py
b/ibus-typing-booster/engine/itb_util.py
index b901db1..9cbc76b 100755
--- a/ibus-typing-booster/engine/itb_util.py
+++ b/ibus-typing-booster/engine/itb_util.py
@@ -3,7 +3,7 @@
#
# ibus-typing-booster - The Tables engine for IBus
#
-# Copyright (c) 2013 Mike FABIAN <mfabian(a)redhat.com>
+# Copyright (c) 2013-2015 Mike FABIAN <mfabian(a)redhat.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -65,3 +65,30 @@ def tokenize(text):
tokens.append(strip_token(s))
return tokens
+def is_ascii(text):
+ '''Checks whether all characters in text are ASCII characters
+
+ Returns ���True��� if the text is all ASCII, ���False��� if not.
+
+ :param text: The text to check
+ :type text: string
+ :rtype: bool
+
+ Examples:
+
+ >>> is_ascii('Abc')
+ True
+
+ >>> is_ascii('Na��ve')
+ False
+ '''
+ try:
+ text.encode('ascii')
+ except UnicodeEncodeError:
+ return False
+ else:
+ return True
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()