📄 test_str.c
字号:
#ifdef _MSC_VER
#include <malloc.h>
#endif
#ifdef __BORLANDC__
#include <alloc.h>
#endif
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hhstring.h"
/* */
/* global variables */
/* */
char part1[80];
char part2[80];
int printflag; /* command line flag controls full */
/* v.s. partial printing */
int ne; /* number of errors */
/* */
/* function prototypes */
/* */
void printline(char *linehead, char *answer, char *OKanswer);
/************************************************************************/
/* */
/* main --- hhstring library test */
/* */
void main(int argc, char *argv[])
{
/* 01234567890123456789 to show character positions */
char *string1 = "time date size other";
char *string2 = " 123456789 ";
char *string3 = "Sample string w/CASE";
char *string4 = " 12345.678 ";
char *string5 = "1eAf57b B13f9";
char *string6 = "sub1 SUB1 sub1";
char *string7 = "text1!text2,text3.so";
char *ans01 = "date size other";
char *ans02 = "time date";
char *ans03 = "size other";
char *ans04 = " time date";
char *ans05 = "size other ";
char *ans06 = " 123456789";
char *ans07 = "123456789 ";
char *ans08 = "size othertime date ";
char *ans09 = "123456789 ";
char *ans10 = " 123456789";
char *ans11 = "123456789";
char *ans12 = "---123456789";
char *ans13 = "123456789---";
char *ans14 = " 123456789 ";
char *ans15 = " 12345678 ";
char *ans16 = " 123456789 ";
char *ans17 = " 12345678 ";
char *ans18 = "--------------------";
char *ans19 = "---- date size other";
char *ans20 = "time date size -----";
char *ans21 = "TIME DATE SIZE OTHER";
char *ans22 = "time size other";
char *ans23 = "timedatesizeother";
char *ans24 = "timdatsizothr";
char *ans25 = "rehto ezis etad emit";
char *ans26 = "time------size other";
char *ans27 = "time----------------";
char *ans28 = "timtsizothr";
char *ans29 = "---123456789--------";
char *ans30 = "other";
char *ans31 = "time new size other";
char *ans32 = "time---size other";
char *ans33 = " 123456789 ";
char *ans34 = " 123456789 ";
char *ans35 = " 12345678 ";
char *ans36 = " 12345678 ";
char *ans37 = "123,456,789";
char *ans38 = "12,345,678";
char *ans39 = "1,234,567";
char *ans40 = " size other";
char *ans41 = "time date ";
char *ans42 = " 123,456,789";
char *ans43 = "ample tring w/CAE";
char *ans44 = "-ample -tring w/CA-E";
char *ans45 = " B13f9";
char work1[80];
char work2[80];
char work3[80];
char work4[80];
char *tempp;
char tempc;
int tempi; /* scratch integer */
unsigned int ii;
int bad_command;
/* */
/* print the header */
/* */
printf( "\n"
"\n Hobbit House utility to test hhstring.lib"
"\n -----------------------------------------\n");
/* */
/* set defaults for command line parameters */
/* */
printflag = 1;
bad_command = 0; /* init bad command flag = off */
/* */
/* parse the command line */
/* */
for(ii = 1; ii < (unsigned)argc; ii++) /* for each of the actual */
/* command line arguments: */
{ tempc = toupper((argv[ii][0])); /* get the command character */
switch(tempc) /* switch on the command char */
{ case 'F': /* case for print flag */
printflag = 0; /* reset the print flag */
break; /* break case F */
default: /* none of the above */
bad_command = 1; /* save the bad command */
break; /* break the default case */
} /* end the argument switch */
/* */
/* if a command line parameter is bad, tell the user and go bye bye */
/* */
if (bad_command) /* if there's a bad cmd */
{ printf("\nthe command \"%s\" does " /* then tell the user what */
"not compute!\n", argv[ii]); /* it was and exit back */
exit(0); /* to DOS */
} /* end if bad command */
} /* end for all args */
if (printflag)
printf("\n\n\n");
/* - - - - - - - - */
/* */
/* atoh */
/* */
ltoa(atoh(" dead "), work1, 16);
printline("atoh #1", work1, "dead");
ltoa(atoh("beef"), work1, 16);
printline("atoh #2", work1, "beef");
/* - - - - - - - - */
/* */
/* atoh2 */
/* */
ltoa(atoh2(&tempi, " dead "), work1, 16);
strrtpad(work1, 4, ' ');
itoa(tempi, work1 + 5, 10);
printline("atoh2 #1", work1, "dead 4");
ltoa(atoh2(&tempi, "1a"), work1, 16);
strrtpad(work1, 4, ' ');
itoa(tempi, work1 + 3, 10);
printline("atoh2 #2", work1, "1a 2");
/* - - - - - - - - */
/* */
/* atolh */
/* */
ltoa(atolh(" deadbeef "), work1, 16);
printline("atolh #1", work1, "deadbeef");
ltoa(atolh("123456789"), work1, 16);
printline("atolh #2", work1, "23456789");
/* - - - - - - - - */
/* */
/* atolh2 */
/* */
ltoa(atolh2(&tempi, " deadbeef "), work1, 16);
strrtpad(work1, 4, ' ');
ltoa(tempi, work1 + 9, 10);
printline("atolh2 #1", work1, "deadbeef 8");
ltoa(atolh2(&tempi, " dead"), work1, 16);
strrtpad(work1, 4, ' ');
ltoa(tempi, work1 + 5, 10);
printline("atolh2 #2", work1, "dead 4");
ltoa(atolh2(&tempi, " 123456789"), work1, 16);
strrtpad(work1, 4, ' ');
ltoa(tempi, work1 + 9, 10);
printline("atolh2 #3", work1, "23456789 9");
/* - - - - - - - - */
/* */
/* atoo */
/* */
ltoa(atoo(" 123456"), work1, 8);
printline("atoo #1", work1, "123456");
ltoa(atoo("18"), work1, 8);
printline("atoo #2", work1, "1");
/* - - - - - - - - */
/* */
/* atoo2 */
/* */
ltoa(atoo2(&tempi, " 123456 "), work1, 8);
strrtpad(work1, 4, ' ');
ltoa(tempi, work1 + 7, 10);
printline("atoo2 #1", work1, "123456 6");
ltoa(atoo2(&tempi, " 18"), work1, 8);
strrtpad(work1, 4, ' ');
ltoa(tempi, work1 + 2, 10);
printline("atoo2 #1", work1, "1 1");
/* - - - - - - - - */
/* */
/* btoc */
/* */
work1[0] = btoc(0);
work1[1] = btoc(1);
work1[2] = EOS;
printline("btoc", work1, "01");
/* - - - - - - - - */
/* */
/* ctob */
/* */
itoa(ctob('0'), work1, 10);
itoa(ctob('1'), work1 + 1, 10);
printline("ctob", work1, "01");
/* - - - - - - - - */
/* */
/* ctod */
/* */
itoa(ctod('0'), work1, 10);
itoa(ctod('9'), work1 + 1, 10);
printline("ctod", work1, "09");
/* - - - - - - - - */
/* */
/* ctoh */
/* */
itoa(ctoh('0'), work1, 16);
itoa(ctoh('f'), work1 + 1, 16);
printline("ctoh", work1, "0f");
/* - - - - - - - - */
/* */
/* dtoc */
/* */
work1[0] = dtoc(0);
work1[1] = dtoc(9);
work1[2] = dtoc(10); /* use error return to insert EOS */
printline("dtoc", work1, "09");
/* - - - - - - - - */
/* */
/* fnconv_1to2 */
/* */
strcpy(work1, "sub1.h");
fnconv_1to2(work1);
printline("fnconv_1to2 #1", work1, "sub1 h ");
strcpy(work1, "thisfile.ext");
fnconv_1to2(work1);
printline("fnconv_1to2 #2", work1, "thisfile ext");
/* - - - - - - - - */
/* */
/* fnconv_2to1 */
/* */
strcpy(work1, "sub1 h ");
fnconv_2to1(work1);
printline("fnconv_2to1 #1", work1, "sub1.h");
strcpy(work1, "thisfile ext");
fnconv_2to1(work1);
printline("fnconv_2to1 #2", work1, "thisfile.ext");
/* - - - - - - - - */
/* */
/* htoc */
/* */
work1[0] = htoc(0);
work1[1] = htoc(15);
work1[2] = htoc(16); /* use error return to put in EOS */
printline("htoc", work1, "0F");
/* - - - - - - - - */
/* */
/* isfilename */
/* */
strcpy(work1, "12345678.9ab");
itoa(isfilename(work1), work2, 10);
strrtsize(work2, 4);
printline("isfilename #1", strcat(work2, work1), "0 12345678.9ab");
strcpy(work1, "*.bak");
itoa(isfilename(work1), work2, 10);
strrtsize(work2, 4);
printline("isfilename #2", strcat(work2, work1), "-1 *.bak");
strcpy(work1, "123<5>78.9ab");
itoa(isfilename(work1), work2, 10);
strrtsize(work2, 4);
printline("isfilename #3", strcat(work2, work1), "-2 123<5>78.9ab");
strcpy(work1, "123456789.ab");
itoa(isfilename(work1), work2, 10);
strrtsize(work2, 4);
printline("isfilename #4", strcat(work2, work1), "-3 123456789.ab");
strcpy(work1, "1234567.89ab");
itoa(isfilename(work1), work2, 10);
strrtsize(work2, 4);
printline("isfilename #5", strcat(work2, work1), "-4 1234567.89ab");
strcpy(work1, "*234*.abc");
itoa(isfilename(work1), work2, 10);
strrtsize(work2, 4);
printline("isfilename #6", strcat(work2, work1), "-5 *234*.abc");
/* - - - - - - - - */
/* */
/* ptrfirstblank */
/* */
printline("ptrfirstblank #1", 1 + ptrfirstblank(string1), ans01);
printline("ptrfirstblank #2", ptrfirstblank("abcd123"), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstchr */
/* */
printline("ptrfirstchr #1", ptrfirstchr(string1, 'd'), string1 + 5);
printline("ptrfirstchr #2", ptrfirstchr(string1, 't'), string1);
printline("ptrfirstchr #3", ptrfirstchr(string1, 'T'), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstchri */
/* */
printline("ptrfirstchri #1", ptrfirstchri(string1, 'D'), string1 + 5);
printline("ptrfirstchri #2", ptrfirstchri(string1, 'T'), string1);
printline("ptrfirstchri #3", ptrfirstchri(string1, 'b'), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstdig */
/* */
printline("ptrfirstdig #1", ptrfirstdig(string2), ans09);
printline("ptrfirstdig #2", ptrfirstdig(string1), NULL);
/* - - - - - - - - */
/* */
/* ptrfirsthex */
/* */
printline("ptrfirsthex #1", ptrfirsthex(string2), ans09);
printline("ptrfirsthex #2", ptrfirsthex(string5 + 9), ans45 + 1);
printline("ptrfirsthex #3", ptrfirsthex("ghijklmn"), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnotblank */
/* */
printline("ptrfirstnotblank #1", ptrfirstnotblank(string2), ans09);
printline("ptrfirstnotblank #2", ptrfirstnotblank(" "), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnotchr */
/* */
printline("ptrfirstnotchr #1", ptrfirstnotchr(string2, ' '), ans09);
printline("ptrfirstnotchr #2", ptrfirstnotchr(ans18, '-'), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnotchri */
/* */
printline("ptrfirstnotchri #1", ptrfirstnotchri(string3, 's'), string3 + 1);
printline("ptrfirstnotchri #2", ptrfirstnotchri("aAaAa", 'a'), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnotdig */
/* */
printline("ptrfirstnotdig #1", ptrfirstnotdig(ans37), ans37 + 3);
printline("ptrfirstnotdig #2", ptrfirstnotdig("123"), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnothex */
/* */
printline("ptrfirstnothex #1", ptrfirstnothex(string5), string5 + 7);
printline("ptrfirstnothex #2", ptrfirstnothex(ans11), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnotrange */
/* */
printline("ptrfirstnotrange #1",
ptrfirstnotrange(ans37, '0', '9'), ans37 + 3);
printline("ptrfirstnotrange #2",
ptrfirstnotrange(string2, ' ', '9'), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnotgr */
/* */
printline("ptrfirstnotgr #1",
ptrfirstnotgr(ans37, "0123456789"), ans37 + 3);
printline("ptrfirstnotgr #2",
ptrfirstnotgr("abcabc", "abc"), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnottextterm */
/* */
printline("ptrfirstnottextterm #1", ptrfirstnottextterm(ans06), ans11);
printline("ptrfirstnottextterm #2", ptrfirstnottextterm(" "), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstnotwhite */
/* */
printline("ptrfirstnotwhite #1", ptrfirstnotwhite(string2), ans09);
printline("ptrfirstnotwhite #2", ptrfirstnotwhite(" "), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstrange */
/* */
printline("ptrfirstrange #1", ptrfirstrange(string1, 'a', 'd'), ans01);
printline("ptrfirstrange #2", ptrfirstrange(string1, 'A', 'Z'), NULL);
printline("ptrfirstrange #3", ptrfirstrange(string2, '9', '0'), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstgr */
/* */
printline("ptrfirstgr #1", ptrfirstgr(string2, "0123456789"), ans09);
printline("ptrfirstgr #2", ptrfirstgr(string1, "0123456789"), NULL);
printline("ptrfirstgr #3", ptrfirstgr(string1, ""), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstsub */
/* */
printline("ptrfirstsub #1", ptrfirstsub(string1, ans30), ans30);
printline("ptrfirstsub #2", ptrfirstsub(string1, "time"), string1);
printline("ptrfirstsub #3", ptrfirstsub(string1, "not here"), NULL);
/* - - - - - - - - */
/* */
/* ptrfirstsubi */
/* */
printline("ptrfirstsubi #1", ptrfirstsubi(ans21, "other"), "OTHER");
printline("ptrfirstsubi #2", ptrfirstsubi(string1, "OTHER"), ans30);
printline("ptrfirstsubi #3", ptrfirstsubi(string1, "not here"), NULL);
/* - - - - - - - - */
/* */
/* ptrfirsttext */
/* */
printline("ptrfirsttext #1", ptrfirsttext(ans04), ans02);
printline("ptrfirsttext #2", ptrfirsttext("!.,;:this"), "this");
printline("ptrfirsttext #3", ptrfirsttext("!.,;:"), NULL);
/* - - - - - - - - */
/* */
/* ptrfirsttextterm */
/* */
printline("ptrfirsttextterm #1", ptrfirsttextterm(string7), string7 + 5);
printline("ptrfirsttextterm #2", ptrfirsttextterm("this:is"), ":is");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -