1 # Copyright 2000 by Jeffrey Chang. All rights reserved.
2 # This code is part of the Biopython distribution and governed by its
3 # license. Please see the LICENSE file that should have been included
4 # as part of this package.
6 """This provides useful general functions for working with strings (DEPRECATED).
8 This module and its C code equivalent are considered to be deprecated, and
9 are likely to be removed in a future release of Biopython. Please get in
10 touch via the mailing list if this will affect you.
13 splitany Split a string using many delimiters.
14 find_anychar Find one of a list of characters in a string.
15 rfind_anychar Find one of a list of characters in a string, from end to start.
19 warnings.warn("Bio.stringfns and its C code equivalent Bio.cstringfns are" \
20 +" deprecated, and will be removed in a future release of"\
21 +" Biopython. If you want to continue to use this code,"\
22 +" please get in contact with the Biopython developers via"\
23 +" the mailing lists to avoid its permanent removal from"\
27 def splitany(s, sep=" \011\012\013\014\015", maxsplit=None, negate=0):
28 """splitany(s [,sep [,maxsplit [,negate]]]) -> list of strings
30 Split a string. Similar to string.split, except that this considers
31 any one of the characters in sep to be a delimiter. If negate is
32 true, then everything but sep will be a separator.
37 for i in range(len(s)):
38 if maxsplit is not None and len(strlist) >= maxsplit:
40 if (s[i] in sep) == (not negate):
41 strlist.append(s[prev:i])
43 strlist.append(s[prev:])
46 def find_anychar(string, chars, index=None, negate=0):
47 """find_anychar(string, chars[, index]) -> index of a character or -1
49 Find a character in string. chars is a list of characters to look
50 for. Return the index of the first occurrence of any of the
51 characters, or -1 if not found. index is the index where the
52 search should start. By default, I search from the beginning of
58 while index < len(string) and \
59 ((not negate and string[index] not in chars) or
60 (negate and string[index] in chars)):
62 if index == len(string):
66 def rfind_anychar(string, chars, index=None, negate=0):
67 """rfind_anychar(string, chars[, index]) -> index of a character or -1
69 Find a character in string, looking from the end to the start.
70 chars is a list of characters to look for. Return the index of
71 the first occurrence of any of the characters, or -1 if not found.
72 index is the index where the search should start. By default, I
73 search from the end of the string.
78 while index >= 0 and \
79 ((not negate and string[index] not in chars) or
80 (negate and string[index] in chars)):
82 # If not found, index will already be -1.
85 # Try and load C implementations of functions. If I can't,
86 # then just ignore and use the pure python implementations.
88 from cstringfns import *