Skip to content

Commit

Permalink
add accents conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
sirfoga committed Oct 14, 2018
1 parent 95869f2 commit f499d41
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
8 changes: 8 additions & 0 deletions docs/source/hal.streams.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Subpackages
Submodules
----------

hal.streams.logger module
-------------------------

.. automodule:: hal.streams.logger
:members:
:undoc-members:
:show-inheritance:

hal.streams.markdown module
---------------------------

Expand Down
8 changes: 8 additions & 0 deletions docs/source/hal.wrappers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,12 @@ hal.wrappers.errors module
:undoc-members:
:show-inheritance:

hal.wrappers.profile module
---------------------------

.. automodule:: hal.wrappers.profile
:members:
:undoc-members:
:show-inheritance:


2 changes: 1 addition & 1 deletion hal/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__description__ = 'Your swiss knife to perform fast and easy pythonic stuff'
__url__ = 'https://sirfoga.github.io/pyhal/'
__version__ = '10.2.6'
__build__ = '03bed5fa194e2c24b9c37fd0eaa5c57a5af4f1c7'
__build__ = '97ad66e38c3abc2ec465853d41fb1acd0bd02a13'
__author__ = 'Stefano Fogarollo'
__author_email__ = 'sirfoga@protonmail.com'
__license__ = 'MIT'
Expand Down
13 changes: 13 additions & 0 deletions hal/strings/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-

"""String models"""
import unicodedata

from pyparsing import Literal, Word, nums, Combine, Optional, delimitedList, \
alphas, oneOf, Suppress
Expand Down Expand Up @@ -38,6 +39,18 @@ def remove_non_ascii(self):
"""
return ''.join(c for c in self.string if ord(c) < 128)

def convert_accents(self):
"""Removes accents from text
:return: input with converted accents chars
"""
nkfd_form = unicodedata.normalize('NFKD', self.string)
return "".join([
char
for char in nkfd_form
if not unicodedata.combining(char)
])

def remove_control_chars(self):
"""Removes controls chars from text
Expand Down
15 changes: 15 additions & 0 deletions tests/test_hal_strings_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,21 @@ def test_remove_escapes():

BatteryTests(tests).assert_all()

@staticmethod
def test_remove_accents():
"""Tests hal.strings.models.String.remove_accents method"""

tests = {
"árvíztűrő tükörfúrógép": "arvizturo tukorfurogep",
"ÁRVÍZTŰRŐ TÜKÖRFÚRÓGÉP": "ARVIZTURO TUKORFUROGEP"
}
tests = {
String(key).convert_accents(): val
for key, val in tests.items()
}

BatteryTests(tests).assert_all()

@staticmethod
def test_remove_non_ascii():
"""Tests hal.strings.models.String.remove_non_ascii method"""
Expand Down

0 comments on commit f499d41

Please sign in to comment.