//
// FILE     : stringtools.js
// TASK     : Contains some functions to manipulate strings.
// PROJECT  : doctronic standard JavaScript libraries.
// AUTHORS  : Ingo Kueper
// VERSION  : V1.00
// DATE     : 2000/06/08
// LAST     : See section "CVS INFO" for revision date.
// COPYRIGHT: (c) 2000 doctronic GmbH & Co. KG
//            Adenauerallee 45-49, D-53332 Bornheim, Germany
//
//--< CVS INFO >-----------------------------------------------------------
//
// $Revision: 1.1 $
// $RCSfile: stringtools.js,v $
// $Date: 2004/02/05 15:39:15 $
// $Author: hamaekers $
//
//--< MODULE INFO >--------------------------------------------------------
//
// Contents:
//   This library file contains some service functions to deal with
//   strings.
//
//     daisySplitString (oString, oDelimiter)
//       Splits the given string using the mentioned delimiter.
//       NOTE: String.split() not used for compatibility.
//
//     daisyStripWhitespaces (oString)
//       Strips leading and appending whitespaces of the given string.
//
// To do:
//
// History:
//   2000/08/30: V1.01: daisySplitString() now returns the number of
//                      substrings found.
//   2000/06/08: First Release.
//
// Known Bugs:
//

//-------------------------------------------------------------------------

//
// {group:StringTools}
//
// SUMMARY: Strip whitespaces.
// TASK   : Strip leading and appending whitespaces of the given string.
// PARAMS : oString - String to remove the whitespaces from.
// RETURNS: A copy of the given string without whitespaces. Returns
//          {tt:null} if the given string is undefined, empty or contains
//          nothing but whitespaces.
//
function daisyStripWhitespaces (oString)
{
  var oResult;


  oResult = null;

  if (daisyStripWhitespaces.arguments.length == 1)
  {
    if (oString != null)
    {
      nBeg         = 0;
      nEnd         = oString.length - 1;
      oWhiteSpaces = unescape ("%09%0A%0D%20");

      if (nEnd >= 0)
      {
        // Strip leading white-spaces.
        while ((nBeg < nEnd) &&
               (oWhiteSpaces.indexOf (oString.charAt (nBeg)) != -1))
        {
          nBeg++;
        };

        // Strip white-spaces at the end of the string.
        while ((nEnd >= nBeg) &&
               (oWhiteSpaces.indexOf (oString.charAt (nEnd)) != -1))
        {
          nEnd--;
        };

        // Anything left?
        if (nEnd >= nBeg)
        {
          oResult = oString.substring (nBeg, nEnd + 1);
        };
      };
    };
  };

  return oResult;
}

//-------------------------------------------------------------------------

//
// {group:StringTools}
//
// SUMMARY: Split the given string.
// TASK   : Split the given string using the mentioned delimiter.
//
//          NOTE: The returned object is *not* of type Array, although it
//                supports the member {tt:length}.
//                ({tt:String.split()} is not used for compatibility.)
//
// PARAMS : oString    - String to split.
//          oDelimiter - Character or string at which {tt:oString} will
//                       be split.
// RETURNS: An array of strings, created by splitting {tt:oString} into
//          substrings, at {tt:oDelimiter} boundaries.
//          Returns {tt:null} if either the given string or the delimiter
//          is undefined or empty.
//
function daisySplitString (oString, oDelimiter)
{
  var aoStrings;


  aoStrings = null;

  if (daisySplitString.arguments.length == 2)
  {
    if ((oString != null) && (oDelimiter != null))
    {
      if ((oString.length > 0) && (oDelimiter.length > 0))
      {
        var nI;
        var nSplitIndex


        nI        = 0;
        aoStrings = new Object ();

        while (true)
        {
          nSplitIndex = oString.indexOf (oDelimiter);

          if (nSplitIndex > -1)
          {
            if (nSplitIndex > 0)
            {
              aoStrings[nI++] = oString.substring (0, nSplitIndex);
            };

            if ((nSplitIndex + oDelimiter.length) < oString.length)
            {
              oString =
                oString.substring (nSplitIndex + oDelimiter.length,
                                   oString.length);
            }

            else
            {
              break;
            };
          }

          else
          {
            if (oString.length > 0)
            {
              aoStrings[nI++] = oString;
            };

            break;
          };
        };

        aoStrings.length = nI;
      };
    };
  };

  return aoStrings;
}

//-------------------------------------------------------------------------

// Check for dependencies and register this library.
if ((typeof (daisyCheckLibrary) != "undefined") &&
    (typeof (daisyCheckLibrary) != "null"))
{
  daisyRegisterLibrary ("StringLib", "1.01");
}

else
{
  alert ("ERROR: Unable to resolve dependencies:\n" +
         "stringtools.js requires daisytools.js!");
};

//-------------------------------------------------------------------------
//-------------------------------------------------------------------------

