1 # -*- coding: utf-8 -*-
5 text = u'ab jd sdflk as sa sadas asdas fsdf '
18 # unicode.split(s, [sep, [maxsplit]])
20 @cython.test_assert_path_exists(
21 "//PythonCapiCallNode")
24 >>> print_all( text.split() )
33 >>> print_all( split(text) )
45 @cython.test_assert_path_exists(
46 "//PythonCapiCallNode")
47 def split_sep(unicode s, sep):
49 >>> print_all( text.split(sep) )
53 >>> print_all( split_sep(text, sep) )
60 @cython.test_fail_if_path_exists(
61 "//CoerceToPyTypeNode",
62 "//CastNode", "//TypecastNode")
63 @cython.test_assert_path_exists(
64 "//CoerceFromPyTypeNode",
65 "//PythonCapiCallNode")
66 def split_sep_max(unicode s, sep, max):
68 >>> print_all( text.split(sep, 1) )
70 sdflk as sa sadas asdas fsdf
71 >>> print_all( split_sep_max(text, sep, 1) )
73 sdflk as sa sadas asdas fsdf
75 return s.split(sep, max)
77 @cython.test_fail_if_path_exists(
78 "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
79 "//CastNode", "//TypecastNode")
80 @cython.test_assert_path_exists(
81 "//PythonCapiCallNode")
82 def split_sep_max_int(unicode s, sep):
84 >>> print_all( text.split(sep, 1) )
86 sdflk as sa sadas asdas fsdf
87 >>> print_all( split_sep_max_int(text, sep) )
89 sdflk as sa sadas asdas fsdf
91 return s.split(sep, 1)
94 # unicode.splitlines(s, [keepends])
96 @cython.test_assert_path_exists(
97 "//PythonCapiCallNode")
98 def splitlines(unicode s):
100 >>> len(multiline_text.splitlines())
102 >>> print_all( multiline_text.splitlines() )
106 >>> len(splitlines(multiline_text))
108 >>> print_all( splitlines(multiline_text) )
113 return s.splitlines()
115 @cython.test_assert_path_exists(
116 "//PythonCapiCallNode")
117 def splitlines_keep(unicode s, keep):
119 >>> len(multiline_text.splitlines(True))
121 >>> print_all( multiline_text.splitlines(True) )
127 >>> len(splitlines_keep(multiline_text, True))
129 >>> print_all( splitlines_keep(multiline_text, True) )
136 return s.splitlines(keep)
138 @cython.test_fail_if_path_exists(
139 "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
140 "//CastNode", "//TypecastNode")
141 @cython.test_assert_path_exists(
142 "//PythonCapiCallNode")
143 def splitlines_keep_bint(unicode s):
145 >>> len(multiline_text.splitlines(True))
147 >>> print_all( multiline_text.splitlines(True) )
153 >>> print_all( multiline_text.splitlines(False) )
157 >>> len(splitlines_keep_bint(multiline_text))
159 >>> print_all( splitlines_keep_bint(multiline_text) )
170 return s.splitlines(True) + ['--'] + s.splitlines(False)
173 # unicode.join(s, iterable)
177 @cython.test_fail_if_path_exists(
178 "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
179 "//CastNode", "//TypecastNode")
180 @cython.test_assert_path_exists(
181 "//PythonCapiCallNode")
182 def join(unicode sep, l):
187 >>> print( pipe_sep.join(l) )
188 ab|jd|sdflk|as|sa|sadas|asdas|fsdf
189 >>> print( join(pipe_sep, l) )
190 ab|jd|sdflk|as|sa|sadas|asdas|fsdf
194 @cython.test_fail_if_path_exists(
195 "//CoerceToPyTypeNode", "//CoerceFromPyTypeNode",
196 "//CastNode", "//TypecastNode", "//NoneCheckNode")
197 @cython.test_assert_path_exists(
198 "//PythonCapiCallNode")
204 >>> print( '|'.join(l) )
205 ab|jd|sdflk|as|sa|sadas|asdas|fsdf
206 >>> print( join_sep(l) )
207 ab|jd|sdflk|as|sa|sadas|asdas|fsdf
212 # unicode.startswith(s, prefix, [start, [end]])
214 @cython.test_fail_if_path_exists(
215 "//CoerceToPyTypeNode",
216 "//CoerceFromPyTypeNode",
217 "//CastNode", "//TypecastNode")
218 @cython.test_assert_path_exists(
219 "//PythonCapiCallNode")
220 def startswith(unicode s, sub):
222 >>> text.startswith('ab ')
224 >>> startswith(text, 'ab ')
226 >>> text.startswith('ab X')
228 >>> startswith(text, 'ab X')
231 >>> text.startswith(('ab', 'ab '))
233 >>> startswith(text, ('ab', 'ab '))
235 >>> text.startswith((' ab', 'ab X'))
237 >>> startswith(text, (' ab', 'ab X'))
240 if s.startswith(sub):
245 @cython.test_fail_if_path_exists(
246 "//CoerceToPyTypeNode",
247 "//CastNode", "//TypecastNode")
248 @cython.test_assert_path_exists(
249 "//CoerceFromPyTypeNode",
250 "//PythonCapiCallNode")
251 def startswith_start_end(unicode s, sub, start, end):
253 >>> text.startswith('b ', 1, 5)
255 >>> startswith_start_end(text, 'b ', 1, 5)
257 >>> text.startswith('b X', 1, 5)
259 >>> startswith_start_end(text, 'b X', 1, 5)
262 if s.startswith(sub, start, end):
268 # unicode.endswith(s, prefix, [start, [end]])
270 @cython.test_fail_if_path_exists(
271 "//CoerceToPyTypeNode",
272 "//CoerceFromPyTypeNode",
273 "//CastNode", "//TypecastNode")
274 @cython.test_assert_path_exists(
275 "//PythonCapiCallNode")
276 def endswith(unicode s, sub):
278 >>> text.endswith('fsdf ')
280 >>> endswith(text, 'fsdf ')
282 >>> text.endswith('fsdf X')
284 >>> endswith(text, 'fsdf X')
287 >>> text.endswith(('fsdf', 'fsdf '))
289 >>> endswith(text, ('fsdf', 'fsdf '))
291 >>> text.endswith(('fsdf', 'fsdf X'))
293 >>> endswith(text, ('fsdf', 'fsdf X'))
301 @cython.test_fail_if_path_exists(
302 "//CoerceToPyTypeNode",
303 "//CastNode", "//TypecastNode")
304 @cython.test_assert_path_exists(
305 "//CoerceFromPyTypeNode",
306 "//PythonCapiCallNode")
307 def endswith_start_end(unicode s, sub, start, end):
309 >>> text.endswith('fsdf', 10, len(text)-1)
311 >>> endswith_start_end(text, 'fsdf', 10, len(text)-1)
313 >>> text.endswith('fsdf ', 10, len(text)-1)
315 >>> endswith_start_end(text, 'fsdf ', 10, len(text)-1)
318 >>> text.endswith(('fsd', 'fsdf'), 10, len(text)-1)
320 >>> endswith_start_end(text, ('fsd', 'fsdf'), 10, len(text)-1)
322 >>> text.endswith(('fsdf ', 'fsdf X'), 10, len(text)-1)
324 >>> endswith_start_end(text, ('fsdf ', 'fsdf X'), 10, len(text)-1)
327 if s.endswith(sub, start, end):
333 # unicode.find(s, sub, [start, [end]])
335 @cython.test_fail_if_path_exists(
336 # "//CoerceFromPyTypeNode",
337 "//CastNode", "//TypecastNode")
338 @cython.test_assert_path_exists(
339 "//CoerceToPyTypeNode",
340 "//PythonCapiCallNode")
341 def find(unicode s, substring):
348 cdef Py_ssize_t pos = s.find(substring)
351 @cython.test_fail_if_path_exists(
352 # "//CoerceFromPyTypeNode",
353 "//CastNode", "//TypecastNode")
354 @cython.test_assert_path_exists(
355 "//CoerceToPyTypeNode",
356 "//PythonCapiCallNode")
357 def find_start_end(unicode s, substring, start, end):
359 >>> text.find('sa', 17, 25)
361 >>> find_start_end(text, 'sa', 17, 25)
364 cdef Py_ssize_t pos = s.find(substring, start, end)
368 # unicode.rfind(s, sub, [start, [end]])
370 @cython.test_fail_if_path_exists(
371 # "//CoerceFromPyTypeNode",
372 "//CastNode", "//TypecastNode")
373 @cython.test_assert_path_exists(
374 "//CoerceToPyTypeNode",
375 "//PythonCapiCallNode")
376 def rfind(unicode s, substring):
380 >>> rfind(text, 'sa')
383 cdef Py_ssize_t pos = s.rfind(substring)
386 @cython.test_fail_if_path_exists(
387 # "//CoerceFromPyTypeNode",
388 "//CastNode", "//TypecastNode")
389 @cython.test_assert_path_exists(
390 "//CoerceToPyTypeNode",
391 "//PythonCapiCallNode")
392 def rfind_start_end(unicode s, substring, start, end):
394 >>> text.rfind('sa', 14, 19)
396 >>> rfind_start_end(text, 'sa', 14, 19)
399 cdef Py_ssize_t pos = s.rfind(substring, start, end)