def splitString()

in scripts/yapl/Utilities.py [0:0]


def splitString(string,separators=StringSeparators):
  """
    The splitString() method is used to create a Jython list from a string of whatever
    is passed in the string.  This could be a list of names or a list of numbers and names
    or whatever.  The string argument can be an string that contains an arbitrary set of 
    substrings separated by the given separators.  
    
    It is often convenient to use a string to represent a list, e.g., on the command line.  
    The separator within that string can be any of the characters provided in the separators 
    argument. The separators argument defaults to those defined in the NameSeparators global 
    for this module. 
    
    The splitString method originated as support for things coming in on the command
    line to a top level script or from a properties file where a multi-valued property
    is needed.
    
    The given string is split into a list based on the separators provided.  Separators 
    defaults to NameSeparators which is comma (,) or space ( ) or a plus (+) character 
    in that order of precedence. If the given string has a comma character in it, the 
    split is done on the comma character. If the given string has a space character in 
    it the split is done on the space character, etc.
    
    NOTE: If the items in the string list have space characters in them, then
    obviously + or , needs to be used to delimit the different items in the
    string.  
    
    With respect to WAS configuration objects we strongly advise against 
    using names that have space characters in the name. Using spaces in names leads 
    to nothing but headaches in scripting.
    
    NOTE: If the incoming string doesn't have any of the separator characters in it, 
    the result is a list with the incoming things string as the only member.  This is 
    behavior patterned after the way the Jython split() method works.
    
    NOTE: To avoid situations where extra space characters are included or somehow 
    an empty item resulted from the split operation, a "clean-up" step is done at the end 
    to filter out any empty values and to strip white space off the items in the result list.  
    This takes care of strings that look like "foo, bar, baz" which would result in 
    ['foo', ' bar', ' baz'] which isn't likely what is wanted.  It also takes care of something 
    that happens to have a double space in it such as "foo  bar baz" which would result in 
    ['foo', '', 'bar', 'baz'] which also isn't likely what is wanted.
  """
  result = []
  
  if (string):
    for char in separators:
      if (string.find(char) > 0):
        result = string.split(char)
        break
      #endIf
    #endFor
  
    if (not result):
      result = [string]
    #endIf
  
    # clean out empty items and any leading or trailing white space
    # on the items in the result list.
    result = [name.strip() for name in result if name]
    
  #endIf
  
  return result