|
TPCCLIB
|
String processing functions. More...
#include "tpcclibConfig.h"#include "tpcextensions.h"#include <stdio.h>#include <stdlib.h>#include <math.h>#include <time.h>#include <string.h>#include <strings.h>#include <ctype.h>Go to the source code of this file.
Functions | |
| int | strTokenNr (const char *s1, const char *s2) |
| int | strTokenNCpy (const char *s1, const char *s2, int i, char *s3, int count) |
| int | strChrCount (const char *s1, const char *s2) |
| int | strUppercaseCount (const char *s) |
| void | strReplaceChar (char *s, char c1, char c2) |
| char * | strcasestr (const char *haystack, const char *needle) |
| char * | strdup (const char *s) |
| char * | strndup (const char *s, size_t n) |
| char * | strstrNoQuotation (const char *haystack, const char *needle) |
| int | strncpyCleanSpaces (char *s1, const char *s2, int maxlen) |
| int | strCleanSpaces (char *s) |
| int | strncpyClean (char *s1, const char *s2, int maxlen) |
| int | strClean (char *s) |
| char * | strTokenDup (const char *s1, const char *s2, int *next) |
| int | strInPars (char *s) |
| void | strCleanPars (char *s) |
| char * | strncatInt (char *str1, const int n, size_t count) |
| char * | strncatDouble (char *str1, const double d, size_t count) |
| char * | strncatIntZ (char *str1, const int n, const int maxn, size_t count) |
| size_t | strnlen (const char *s, size_t n) |
| size_t | strlcat (char *dst, const char *src, size_t dstsize) |
| size_t | strlcpy (char *dst, const char *src, size_t dstsize) |
| int | strIsSpaceOnly (char *s) |
| char * | strdelstr (char *s1, const char *s2) |
| char * | strTrimLeft (char *s, const size_t t) |
| char * | strEncodeForXML (const char *s) |
| void | strCleanForXML (char *s) |
String processing functions.
Definition in file stringext.c.
| char * strcasestr | ( | const char * | haystack, |
| const char * | needle ) |
Case-insensitive version of strstr().
| haystack | Pointer to string in which sub-string needle is searched. |
| needle | Pointer to sub-string which is searched for in source string haystack. |
Definition at line 155 of file stringext.c.
Referenced by csvSearchField(), dcmImgIsotope(), dcmMListRead(), elementIdentify(), iftSearchKey(), iftSearchValue(), imgFormatFromFName(), parFormatFromExtension(), parReadRES(), parWriteRES(), strdelstr(), tacReadInveonCSV(), tacSelectBestReference(), tacWritePMOD(), tacWriteXML(), and unitIdentifyFilename().
| int strChrCount | ( | const char * | s1, |
| const char * | s2 ) |
Count how many times characters specified in string s2 are found in string s1.
Search is case-sensitive.
| s1 | String to search for characters; not modified. |
| s2 | String containing characters which are searched for; not modified. |
Definition at line 98 of file stringext.c.
Referenced by strncpyClean().
| int strClean | ( | char * | s | ) |
Removes any initial and trailing space characters from specified string s. Removes also quotation marks ("" or '') that may be around the string s. Quotes or space characters in the middle of the string are not removed.
| s | Pointer to the string. |
Definition at line 389 of file stringext.c.
Referenced by iftPutFromString(), iftPutFromStringWithSpaceSeparator(), imgReadDICOM(), tacNameSplit(), and tacRead4DM().
| void strCleanForXML | ( | char * | s | ) |
Remove from string those characters that would require encoding in XML. Replaced by character '-'.
| s | Pointer to the string to be cleaned. |
Definition at line 769 of file stringext.c.
| void strCleanPars | ( | char * | s | ) |
Remove parenthesis (s), [s], or {s} from around the string s.
Only one set of pars are removed, and only if the same pars are as the first and last character of the string.
| s | Pointer to the string. |
Definition at line 476 of file stringext.c.
Referenced by iftGetDoubleWithUnit(), tacRead4DM(), tacReadCarimasTxt(), and tacReadDFT().
| int strCleanSpaces | ( | char * | s | ) |
Removes any initial and trailing space characters from specified string s. Space characters in the middle of the string are not removed.
| s | Pointer to the string. |
Definition at line 300 of file stringext.c.
Referenced by csvCleanSpaces(), dcmImgIsotope(), and strncpyClean().
| char * strdelstr | ( | char * | s1, |
| const char * | s2 ) |
Find (case-insensitive) s2 in s1, and delete it from s1.
| s1 | Pointer to string in which sub-string s2 is searched; modified. |
| s2 | Pointer to sub-string which is searched for in source string s1. |
Definition at line 688 of file stringext.c.
| char * strdup | ( | const char * | s | ) |
Allocates memory and copies into it the string addressed by s, including the terminating character.
| s | String to be duplicated. |
Definition at line 185 of file stringext.c.
Referenced by atofCheck(), atofVerified(), csvCellReplace(), csvDuplicate(), csvPutString(), dcmFileList(), dcmMListRead(), iftPut(), iftPutFromString(), iftPutFromStringWithSpaceSeparator(), iftReplaceKey(), iftReplaceValue(), parCombineTACs(), parCompareParameterNames(), parCompareTacNames(), parSelectByAnother(), pathCreate(), pathExist(), roinameSubpart(), statusSet(), strCleanSpaces(), strTokenDup(), studynrFromFilename(), tacNameSplit(), tacRead(), tacReadCarimasTxt(), tacReadCSV(), tacReadDFT(), tacReadHRRTHC(), tacReadPMOD(), tpcHtmlUsage(), tpcPrintBuild(), tpcPrintUsage(), and tpcProgramName().
| char * strEncodeForXML | ( | const char * | s | ) |
Encode special characters for XML, including SVG.
| s | Pointer to the string to be encoded. |
Definition at line 731 of file stringext.c.
Referenced by parWriteXML(), and tacWriteXML().
| int strInPars | ( | char * | s | ) |
Checks whether string is inside parenthesis (s), [s], or {s}, that is, the same pars as the first and last character of the string.
| s | Pointer to the string. |
Definition at line 453 of file stringext.c.
Referenced by strCleanPars(), and tacReadDFT().
| int strIsSpaceOnly | ( | char * | s | ) |
Checks whether string contains only space characters.
Text files saved in text editor or Excel may accidentally contain empty looking lines which still may contain tabs and spaces, leading to problems when reading them for example as CSV files.
| s | Pointer to the string. |
Definition at line 671 of file stringext.c.
Referenced by csvRead().
| size_t strlcat | ( | char * | dst, |
| const char * | src, | ||
| size_t | dstsize ) |
Safer version of strncat.
At most dstsize-1 characters are appended from the source string to destination string. Destination string will be NUL terminated, unless dstsize <= strlen(dst).
| dst | Destination string. |
| src | Source string. |
| dstsize | The actual length of buffer allocated for the destination string; for example, destination string has been allocated as char dst[dstsize]; |
Definition at line 592 of file stringext.c.
Referenced by fileBackup(), micropetExists(), parReadFIT(), parReadRES(), roinameAddField(), roinameEditByTemplate(), roinameSubpart(), and tpcProgramName().
| size_t strlcpy | ( | char * | dst, |
| const char * | src, | ||
| size_t | dstsize ) |
Safer version of strncpy or strcpy.
At most dstsize-1 characters are copied from the source string to destination string. Destination string will be NUL terminated.
| dst | Destination string. |
| src | Source string. |
| dstsize | The actual length of buffer allocated for the destination string; for example, destination string has been allocated as char dst[dstsize]; |
Definition at line 632 of file stringext.c.
Referenced by abssWrite(), anaExists(), dcmAddItem(), dcmFileRead(), dcmMListRead(), dcmSameImage(), ecatReadMainheader(), ecatWriteMainheader(), fileBackup(), imgCopyHeader(), imgSetNiftiHeader(), imgWriteNifti(), micropetExists(), niftiCreateFNames(), niftiExists(), parReadCSV(), parReadFIT(), parReadRES(), parWriteFIT(), roinameAddField(), strDateRead(), strDateTimeValid(), strncpyClean(), strncpyCleanSpaces(), strTokenDup(), strTokenNCpy(), studynrFromFilename(), tacGetHeaderIsotope(), tacGetHeaderStudynr(), tacNameSplit(), tacRead4DM(), tacReadCarimasTxt(), tacReadCSV(), tacReadDFT(), tacReadInveonCSV(), tacReadMat(), tacReadOldAllogg(), tacReadPMOD(), tacReadQView(), tacReadSIF(), tacReadSimple(), and tpcProgramName().
| char * strncatDouble | ( | char * | str1, |
| const double | d, | ||
| size_t | count ) |
Concatenate not more than count characters of the string representation of double d to the string pointed to by str1. String is terminated with a null.
| str1 | String to be catenated. |
| d | Double value to be catenated as string into str1. |
| count | No more than count characters are concatenated to str1. If str1 was allocated like char str1[MAX_LEN], then set count=MAX_LEN-strlen(str1)-1. |
Definition at line 517 of file stringext.c.
| char * strncatInt | ( | char * | str1, |
| const int | n, | ||
| size_t | count ) |
Concatenate not more than count characters of the string representation of integer n to the string pointed to by str1. String is terminated with a null.
| str1 | String to be catenated. |
| n | Integer value to be catenated as string into str1. |
| count | No more than count characters are concatenated to str1. If str1 was allocated like char str1[MAX_LEN], then set count=MAX_LEN-strlen(str1)-1. |
Definition at line 495 of file stringext.c.
| char * strncatIntZ | ( | char * | str1, |
| const int | n, | ||
| const int | maxn, | ||
| size_t | count ) |
Concatenate not more than count characters of the zero-padded string representation of integer n to the string pointed to by str1. String is terminated with a null.
| str1 | String to be catenated. |
| n | Integer value to be catenated as string into str1. |
| maxn | Integer value which is large enough that it would not need to be zero-padded. |
| count | No more than count characters are concatenated to str1. If str1 was allocated like char str1[MAX_LEN], then set count=MAX_LEN-strlen(str1)-1. |
Definition at line 539 of file stringext.c.
| int strncpyClean | ( | char * | s1, |
| const char * | s2, | ||
| int | maxlen ) |
Version of strncpy() which as usual copies s2 to s1, but without any quotation marks ("" or ''), space characters, or line end characters that may be around the string s2.
| s1 | Pointer to pre-allocated result string with length of at least maxlen characters, including NULL character. |
| s2 | Pointer to the original string. |
| maxlen | Max length of s1, including the trailing zero. |
Definition at line 321 of file stringext.c.
Referenced by imgReadDICOM(), parSelectParameters(), parSelectTACs(), strClean(), and tacSelectTACs().
| int strncpyCleanSpaces | ( | char * | s1, |
| const char * | s2, | ||
| int | maxlen ) |
Version of strncpy() which as usual copies s2 to s1, but without any space characters or line end characters that may be around the string s2.
| s1 | Pointer to pre-allocated result string with length of at least maxlen characters, including NULL character. |
| s2 | Pointer to the original string. |
| maxlen | Max length of s1, including the trailing zero. |
Definition at line 265 of file stringext.c.
Referenced by niftiBasename(), parReadFIT(), strCleanSpaces(), strncpyClean(), and tacRead4DM().
| char * strndup | ( | const char * | s, |
| size_t | n ) |
Allocates memory and copies into it first n characters from string addressed by s, and adds the terminating character.
| s | String to be duplicated. |
| n | Max nr of characters to copy, not including terminal zero. |
Definition at line 205 of file stringext.c.
Referenced by csvPutLine(), csvPutLineWithSpaces(), iftPutFromString(), iftPutFromStringWithSpaceSeparator(), and tpcProgramName().
| size_t strnlen | ( | const char * | s, |
| size_t | n ) |
Safer version of strlen, in case the argument s is not NUL terminated string. Computes the length of string s, but never scans beyond the n first bytes of the string.
| s | Pointer to string, or character array, that may not be NULL terminated. |
| n | The actual length of buffer allocated for the string; for example, string could have been allocated as char s[n]; |
Definition at line 566 of file stringext.c.
Referenced by abssIdFromFName(), anaExists(), anaReadHeader(), atoiCheck(), dcmAddItem(), dcmDA2intl(), dcmDT2intl(), dcmFileList(), dcmFileRead(), dcmFileRemove(), dcmFileWrite(), dcmSOPIdentify(), dcmSOPUIDName(), dcmTM2intl(), dcmTrUID(), elementIdentify(), fileExist(), filenameGetExtension(), filenameGetExtensions(), filenameRmExtension(), filenameRmExtensions(), filenameRmFile(), filenameRmPath(), imgFormatFromFName(), imgRead(), imgReadDICOM(), imgReadNifti(), imgWrite(), imgWriteDICOM(), imgWriteNifti(), isotopeIdentify(), micropetExists(), micropetHeaderRead(), mtgaPlotSVG(), niftiExists(), niftiReadHeader(), niftiWriteHeader(), parCombineTACs(), parSelectByAnother(), parWriteFIT(), pathCreate(), pathFileList(), pathFileNr(), roinameMatch(), roinameSubpart(), strDateRead(), strDateTimeValid(), strDateValid(), strDateValid2(), strDateValid3(), strIsValidNumber(), strlcat(), strndup(), strTimeValid(), strTokenNr(), studynrFromFilename(), tacPlotFitSVG(), tacPlotHistogramSVG(), tacPlotLineSVG(), tacReadAllogg(), tacReadGEMS(), tacReadMat(), tacReadModelingData(), tacReadModelingInput(), tacReadOldAllogg(), tacReadQView(), tacReadReference(), tacReadScanditronics(), tpcHtmlUsage(), tpcProcessStdOptions(), tpcProgramName(), tpcYesNo(), unitIdentify(), and unitIdentifyFilename().
| void strReplaceChar | ( | char * | s, |
| char | c1, | ||
| char | c2 ) |
Replace all characters c1 in string s with character c2.
| s | Pointer to string in which the character is replaced. |
| c1 | Character to be replaced. |
| c2 | Character to use instead. If NULL, then only the first character is replaced. |
Definition at line 134 of file stringext.c.
Referenced by csvPutDouble(), parCombineTACs(), parCompareParameterNames(), parCompareTacNames(), parSelectByAnother(), parToIFT(), strCleanForXML(), and tacWritePMOD().
| char * strstrNoQuotation | ( | const char * | haystack, |
| const char * | needle ) |
Version of strstr() which ignores any matches inside quotation marks "" or ''.
| haystack | Pointer to string to be searched. |
| needle | Pointer to string with quotation marks. |
Definition at line 225 of file stringext.c.
Referenced by csvRead(), iftPutFromString(), and iftPutFromStringWithSpaceSeparator().
| char * strTokenDup | ( | const char * | s1, |
| const char * | s2, | ||
| int * | next ) |
Search the string s1 for the first token. The characters making up the string s2 are the delimiters that determine the tokens.
| s1 | String from where tokens are searched; not modified in any way. |
| s2 | String containing character delimiters. |
| next | Index of s1 where the token ended; set to NULL, if not needed. |
Definition at line 413 of file stringext.c.
Referenced by csvRead(), iftRead(), tacFormatDetermine(), and tacRead4DM().
| int strTokenNCpy | ( | const char * | s1, |
| const char * | s2, | ||
| int | i, | ||
| char * | s3, | ||
| int | count ) |
Copy the i'th token in the string s1 into string s3. The characters making up the string s2 are the delimiters that determine the tokens.
| s1 | String from where tokens are searched; not modified in any way. |
| s2 | String containing character delimiters. |
| i | Token number to copy (1..nr of tokens). |
| s3 | String array into where the token is copied; string will be null terminated. |
| count | Length of s3, including terminal null. |
Definition at line 53 of file stringext.c.
Referenced by atofList(), doubleGetWithUnit(), floatGetWithUnit(), iftGetDoubleWithUnit(), intlistAddFromString(), intlistExpandFromString(), parFromIFT(), parReadCSV(), parReadRES(), and tacReadSIF().
| int strTokenNr | ( | const char * | s1, |
| const char * | s2 ) |
Calculate the number of tokens in the string s1. The characters making up the string s2 are the delimiters that determine the token.
| s1 | String from where tokens are calculated; not modified in any way. |
| s2 | String containing character delimiters. |
Definition at line 25 of file stringext.c.
Referenced by atofList(), doubleGetWithUnit(), floatGetWithUnit(), intlistAddFromString(), intlistExpandFromString(), parFromIFT(), parReadRES(), and tacNameSplit().
| char * strTrimLeft | ( | char * | s, |
| const size_t | t ) |
Strip string of t characters from the left.
| s | Pointer to the string to be trimmed. Overwritten. |
| t | Number of characters to remove. |
Definition at line 710 of file stringext.c.
| int strUppercaseCount | ( | const char * | s | ) |
Count how many upper case characters are found in string.
| s | String to search for upper case characters; not modified. |
Definition at line 118 of file stringext.c.