home *** CD-ROM | disk | FTP | other *** search
- /*********************
- *
- * st_conv.c - string conversion functions.
- *
- * Purpose: This file contains some commonly used conversion routines
- * for ascii strings.
- *
- * Blackstar C Function Library
- * (c) Copyright 1985,1989 Sterling Castle Software
- *
- *******/
-
- #include <ctype.h>
- #include "blackstr.h"
-
-
- /********
- *
- * st_toi(str) - string to integer conversion
- *
- **/
-
- int st_toi(char *str)
- {
- int n,sign;
-
- n = 0;
- while(isspace(*str)) /* skip leading whitespace */
- ++str;
- sign = 1;
- if(*str == '+' || *str== '-')
- sign = (*str++=='+') ? 1 : -1; /* multiplier for sign */
- for( ; *str >= '0' && *str<='9'; ++str)
- n = 10 * n + *str - '0';
- return(n*sign);
- }
-
-
- /********
- *
- * st_tol(str) - string to long conversion
- *
- **/
- long st_tol(char *str)
- {
- int sign;
- long n;
-
- n = 0L;
- while(isspace(*str)) /* skip leading whitespace */
- ++str;
- sign = 1;
- if(*str == '+' || *str== '-')
- sign = (*str++=='+') ? 1 : -1; /* multiplier for sign */
- for( ; *str >= '0' && *str<='9'; ++str)
- n = 10L * n + *str - '0';
- return(n*(long)sign);
- }
-
-
- /********
- *
- * st_tof(str) - string to float conversion
- *
- **/
-
- float st_tof(char *str)
- {
- int sign;
- float n;
-
- n = 0L;
- while(isspace(*str)) /* skip leading whitespace */
- ++str;
- sign = 1;
- if(*str == '+' || *str== '-')
- sign = (*str++=='+') ? 1 : -1; /* multiplier for sign */
- for( ; *str >= '0' && *str<='9'; ++str)
- n = 10L * n + *str - '0';
- return((float)(n*sign));
- }
-
-
- /********
- *
- * st_upper(str) - convert string to upper case
- *
- **/
-
- char *st_upper(char *str) /* string to convert */
- {
- char *ptr;
-
- ptr = str;
- while(*str) {
- if(*str >= 'a' && *str <= 'z') *str = toupper(*str);
- ++str;
- }
- return(ptr);
- }
-
-
- /********
- *
- * st_lower(str) - convert string to lower case
- *
- **/
-
- char *st_lower(char *str) /* string to convert */
- {
- char *ptr;
-
- ptr = str;
- while(*str) {
- *str = tolower(*str);
- ++str;
- }
- return(ptr);
- }
-