int main (int argc, char **argv) { char buffer[] = "Hello , World, This, is, a , test\n"; char buffer2[] = ""; size_t listLen = 0; char **List = NULL; size_t i; size_t j; char ans; double value; char *tail; /* printf ("1 :: %f\n", clock() / (double) (CLOCKS_PER_SEC)); for (j = 0; j < 25000; j++) { mySplit (buffer, ',', &listLen, &List, 1); for (i = 0; i < listLen; i++) { free (List[i]); } free (List); List = NULL; listLen = 0; } printf ("1 :: %f\n", clock() / (double) (CLOCKS_PER_SEC)); */ mySplit (buffer, ',', &listLen, &List, 1); for (i = 0; i < listLen; i++) { printf ("%d:'%s'\n", i, List[i]); free (List[i]); } free (List); List = NULL; listLen = 0; mySplit (buffer2, ',', &listLen, &List, 1); for (i = 0; i < listLen; i++) { printf ("%d:'%s'\n", i, List[i]); free (List[i]); } free (List); List = NULL; listLen = 0; strcpy (buffer, " 0.95"); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, "0.95"); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, "+0.95"); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, "0.95, "); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, "0.95,"); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, "0.9.5"); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, " alph 0.9.5"); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, " "); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); strcpy (buffer, ""); ans = myAtoF (buffer, &value); printf ("%d %f : ", ans, value); ans = myIsReal_old (buffer, &value); printf ("%d %f : '%s'\n", ans, value, buffer); tail = NULL; FileTail ("test\\me/now", &tail); printf ("%s \n", tail); free (tail); tail = NULL; FileTail ("test/me\\now", &tail); printf ("%s \n", tail); free (tail); strcpy (buffer, " here "); strTrim (buffer); printf ("%s\n", buffer); strcpy (buffer, " here "); strCompact (buffer, ' '); printf ("'%s'\n", buffer); return 0; }
bool Get_XML_double (CXMLelement & node, const char * sName, double & dValue, const bool bUseDefault, const double dMinimum, const double dMaximum) { CString strValue; if (!Get_XML_string (node, sName, strValue, bUseDefault)) if (bUseDefault) return false; else strValue = "0"; // default is zero double dResult = 0; const char * p = strValue; int iDots = 0; int iExponents = 0; // see if sign given if (*p == '-' || *p == '+') p++; if (*p == 0) ThrowErrorException ("No number suppied for numeric attribute named '%s'" , sName); if (!isdigit (*p)) ThrowErrorException ("Invalid number \"%s\" for numeric attribute named '%s'" , (LPCTSTR) strValue, sName); for ( ; *p; p++) { if (*p == '.') { if (++iDots > 1) ThrowErrorException ("Too many decimal places for numeric attribute named '%s'" , sName); } // end of decimal place else if (toupper (*p) == 'E') { if (++iExponents > 1) ThrowErrorException ("Too many 'E' characters for numeric attribute named '%s'" , sName); // exponent may have sign if (*p == '-' || *p == '+') p++; } // end of exponent else if(!isdigit (*p)) ThrowErrorException ("Invalid character '%c' in numeric attribute named '%s'" , *p, sName); } // end of checking each character myAtoF (strValue, &dResult); /* // myAtoF does not return myAtoF if (dResult == c || dResult == -HUGE_VAL) ThrowErrorException ("Value '%s' out of range in numeric attribute named '%s'" , (LPCTSTR) strValue, sName); */ if (dResult > dMaximum) ThrowErrorException ("Value '%s' too large in numeric attribute named '%s'. " "Range is %g to %g.", (LPCTSTR) strValue, sName, dMinimum, dMaximum); if (dResult < dMinimum) ThrowErrorException ("Value '%s' too small in numeric attribute named '%s'. " "Range is %g to %g.", (LPCTSTR) strValue, sName, dMinimum, dMaximum); dValue = dResult; return true; } // end of Get_XML_double