format string doc

This commit is contained in:
Prodesire 2017-12-13 22:01:14 +08:00
parent 8f20d7d4f2
commit 74ccb78b4a
1 changed files with 40 additions and 40 deletions

View File

@ -3,73 +3,73 @@ String
.. py:function:: pydu.string.safeunicode(obj, encoding='utf-8') .. py:function:: pydu.string.safeunicode(obj, encoding='utf-8')
Converts any given object to unicode string. Converts any given object to unicode string.
>>> from pydu.string import safeunicode >>> from pydu.string import safeunicode
>>> safeunicode('hello') >>> safeunicode('hello')
u'hello' u'hello'
>>> safeunicode(2) >>> safeunicode(2)
u'2' u'2'
>>> safeunicode('\xe4\xb8\xad\xe6\x96\x87') >>> safeunicode('\xe4\xb8\xad\xe6\x96\x87')
u'中文' u'中文'
.. py:function:: pydu.string.safeencode(obj, encoding='utf-8') .. py:function:: pydu.string.safeencode(obj, encoding='utf-8')
Converts any given object to encoded string (default: utf-8). Converts any given object to encoded string (default: utf-8).
>>> from pydu.string import safeencode >>> from pydu.string import safeencode
>>> safeencode('hello') >>> safeencode('hello')
'hello' 'hello'
>>> safeencode(2) >>> safeencode(2)
'2' '2'
>>> safeencode(u'中文') >>> safeencode(u'中文')
'\xe4\xb8\xad\xe6\x96\x87' '\xe4\xb8\xad\xe6\x96\x87'
.. py:function:: pydu.string.lstrips(text, remove) .. py:function:: pydu.string.lstrips(text, remove)
Removes the string ``remove`` from the left of ``text``. Removes the string ``remove`` from the left of ``text``.
>>> from pydu.string import lstrips >>> from pydu.string import lstrips
>>> lstrips('foobar', 'foo') >>> lstrips('foobar', 'foo')
'bar' 'bar'
>>> lstrips('FOOBARBAZ', ['FOO', 'BAR']) >>> lstrips('FOOBARBAZ', ['FOO', 'BAR'])
'BAZ' 'BAZ'
>>> lstrips('FOOBARBAZ', ['BAR', 'FOO']) >>> lstrips('FOOBARBAZ', ['BAR', 'FOO'])
'BARBAZ' 'BARBAZ'
.. py:function:: pydu.string.rstrips(text, remove) .. py:function:: pydu.string.rstrips(text, remove)
Removes the string ``remove`` from the right of ``text``. Removes the string ``remove`` from the right of ``text``.
>>> from pydu.string import rstrips >>> from pydu.string import rstrips
>>> rstrips('foobar', 'bar') >>> rstrips('foobar', 'bar')
'foo' 'foo'
.. py:function:: pydu.string.strips(text, remove) .. py:function:: pydu.string.strips(text, remove)
Removes the string ``remove`` from the both sides of ``text``. Removes the string ``remove`` from the both sides of ``text``.
>>> from pydu.string import strips >>> from pydu.string import strips
>>> strips('foobarfoo', 'foo') >>> strips('foobarfoo', 'foo')
'bar' 'bar'
.. py:function:: pydu.string.common_prefix(l) .. py:function:: pydu.string.common_prefix(l)
Return common prefix of the stings Return common prefix of the stings
>>> from pydu.string import common_prefix >>> from pydu.string import common_prefix
>>> common_prefix(['abcd', 'abc1']) >>> common_prefix(['abcd', 'abc1'])
'abc' 'abc'
.. py:function:: pydu.string.common_suffix(l) .. py:function:: pydu.string.common_suffix(l)
Return common suffix of the stings Return common suffix of the stings
>>> from pydu.string import common_suffix >>> from pydu.string import common_suffix
>>> common_suffix(['dabc', '1abc']) >>> common_suffix(['dabc', '1abc'])
'abc' 'abc'