View Raw SPL
/*****************************************************************************
*                                                                            *
*   ISDSNAME.SPL Copyright (C) 2008-2013 DSP Development Corporation         *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Checks if string in dataset.ver.series format               *
*                                                                            *
*   Revisions:   14 Mar 2008  RRR  Creation                                  *
*                10 May 2013  RRR  parse update                              *
*                                                                            *
*****************************************************************************/

#include 

#if @HELP_ISDSNAME

    ISDSNAME

    Purpose: Checks if a string is in dataset.ver.series format.

    Syntax:  ISDSNAME(str)

                str - A string, the text to check.

    Returns:
             An integer, 1 if successful else 0.

    Example:
             a = isdsname("RUN1");
             b = isdsname("RUN1.1X1.ANALOG1");
             c = isdsname("RUN1.1.ANALOG1");

             Both a and b are 0 indicating the string is not in valid
             dataset.ver.series format and c == 1, indicating the string
             represents a valid dataset/series name.

    Remarks:
             ISDSNAME checks if the input string is in dataset.ver.series
             format where ver must be integer. This format represents a
             valid name for an internally saved series.

             ISDSNAME returns 0 if the input is not a string.

             See ISWINDS to check if a window contains a directly loaded
             saved series.
   See Also:
             ISWINDS
             STRGET
#endif


/* is string in dataset.ver.series format? */
isdsname(str)
{
        local status, name, ver, verstr;

        status = 0;

        if (argc > 0)
        {
                /* requires string input */
                if (isstring(str))
                {
                        /* parse to: dataset.ver.series where ver must be an integer */
                        name = strget(1, str, ".");
                        
                        if (isdsname_valid(name))
                        {
                                verstr = strget(2, str, ".");
                                ver    = castint(verstr);
                                
                                /* check if verstr represents a positive integer */
                                if (ver > 0 && caststring(ver) == verstr)
                                {
                                        /* check series name component */
                                        name = strfind(".", str);

                                        if (strlen(name) > 0)
                                        {
                                                name = strfind(".", strextract(name, 2, -1));

                                                if (strlen(name) > 0)
                                                {
                                                        name = strextract(name, 2, -1);
                                        
                                                        if (isdsname_valid(name))
                                                        {
                                                                status = 1;
                                                        }
                                                }
                                        }
                                }
                        }
                }
        }
        
        return(status);
}


/* does string represent a valid dataset or series name? */
isdsname_valid(str)
{
        local status = FALSE;

        if (strlen(str) > 0)
        {
                /* check for invalid characters */
                if (strlen(strfind("(", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind(")", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind("[", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind("]", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind(" ", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind(".", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind("*", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind("+", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind("-", str)) > 0)
                {
                        status = FALSE;
                }
                else if (strlen(strfind("/", str)) > 0)
                {
                        status = FALSE;
                }
                else
                {
                        status = TRUE;
                }
        }
        
        return(status);
}