##// END OF EJS Templates
Remove more unused functions from utils.text
Thomas Kluyver -
Show More
@@ -36,18 +36,6 b' from IPython.utils.data import flatten'
36 # Code
36 # Code
37 #-----------------------------------------------------------------------------
37 #-----------------------------------------------------------------------------
38
38
39 def unquote_ends(istr):
40 """Remove a single pair of quotes from the endpoints of a string."""
41
42 if not istr:
43 return istr
44 if (istr[0]=="'" and istr[-1]=="'") or \
45 (istr[0]=='"' and istr[-1]=='"'):
46 return istr[1:-1]
47 else:
48 return istr
49
50
51 class LSString(str):
39 class LSString(str):
52 """String derivative with a special access attributes.
40 """String derivative with a special access attributes.
53
41
@@ -269,58 +257,6 b' class SList(list):'
269 # print_slist = result_display.when_type(SList)(print_slist)
257 # print_slist = result_display.when_type(SList)(print_slist)
270
258
271
259
272 def esc_quotes(strng):
273 """Return the input string with single and double quotes escaped out"""
274
275 return strng.replace('"','\\"').replace("'","\\'")
276
277
278 def qw(words,flat=0,sep=None,maxsplit=-1):
279 """Similar to Perl's qw() operator, but with some more options.
280
281 qw(words,flat=0,sep=' ',maxsplit=-1) -> words.split(sep,maxsplit)
282
283 words can also be a list itself, and with flat=1, the output will be
284 recursively flattened.
285
286 Examples:
287
288 >>> qw('1 2')
289 ['1', '2']
290
291 >>> qw(['a b','1 2',['m n','p q']])
292 [['a', 'b'], ['1', '2'], [['m', 'n'], ['p', 'q']]]
293
294 >>> qw(['a b','1 2',['m n','p q']],flat=1)
295 ['a', 'b', '1', '2', 'm', 'n', 'p', 'q']
296 """
297
298 if isinstance(words, basestring):
299 return [word.strip() for word in words.split(sep,maxsplit)
300 if word and not word.isspace() ]
301 if flat:
302 return flatten(map(qw,words,[1]*len(words)))
303 return map(qw,words)
304
305
306 def qwflat(words,sep=None,maxsplit=-1):
307 """Calls qw(words) in flat mode. It's just a convenient shorthand."""
308 return qw(words,1,sep,maxsplit)
309
310
311 def qw_lol(indata):
312 """qw_lol('a b') -> [['a','b']],
313 otherwise it's just a call to qw().
314
315 We need this to make sure the modules_some keys *always* end up as a
316 list of lists."""
317
318 if isinstance(indata, basestring):
319 return [qw(indata)]
320 else:
321 return qw(indata)
322
323
324 def indent(instr,nspaces=4, ntabs=0, flatten=False):
260 def indent(instr,nspaces=4, ntabs=0, flatten=False):
325 """Indent a string a given number of spaces or tabstops.
261 """Indent a string a given number of spaces or tabstops.
326
262
General Comments 0
You need to be logged in to leave comments. Login now