1 /* @include ajstr ************************************************************* 2 ** 3 ** AJAX string functions 4 ** 5 ** AJAX string AjPStr objects are reference counted strings 6 ** Any change will need a new string object if the use count 7 ** is greater than 1, so the original AjPStr is provided as a pointer 8 ** so that it can be reallocated in any routine where string modification 9 ** may be needed. 10 ** 11 ** In many cases the text is always a copy, even of a constant original, so 12 ** that it can be simply freed. 13 ** 14 ** @author Copyright (C) 1998 Peter Rice 15 ** @version $Revision: 1.103 $ 16 ** @modified 1998-2011 Peter Rice 17 ** @modified $Date: 2012/12/07 09:52:11 $ by $Author: rice $ 18 ** @@ 19 ** 20 ** This library is free software; you can redistribute it and/or 21 ** modify it under the terms of the GNU Lesser General Public 22 ** License as published by the Free Software Foundation; either 23 ** version 2.1 of the License, or (at your option) any later version. 24 ** 25 ** This library is distributed in the hope that it will be useful, 26 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 27 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 28 ** Lesser General Public License for more details. 29 ** 30 ** You should have received a copy of the GNU Lesser General Public 31 ** License along with this library; if not, write to the Free Software 32 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 33 ** MA 02110-1301, USA. 34 ** 35 ******************************************************************************/ 36 37 #ifndef AJSTR_H 38 #define AJSTR_H 39 40 /* ========================================================================= */ 41 /* ============================= include files ============================= */ 42 /* ========================================================================= */ 43 44 #include "ajdefine.h" 45 46 AJ_BEGIN_DECLS 47 48 49 50 51 /* ========================================================================= */ 52 /* =============================== constants =============================== */ 53 /* ========================================================================= */ 54 55 56 57 58 /* ========================================================================= */ 59 /* ============================== public data ============================== */ 60 /* ========================================================================= */ 61 62 63 64 65 /* @data AjPStr *************************************************************** 66 ** 67 ** Ajax string object. 68 ** 69 ** Holds a null terminated character string with additional data. 70 ** The length is known and held internally. 71 ** The reserved memory size is known and held internally. 72 ** The reference count is known and held internally. 73 ** New pointers can refer to the same string without needing 74 ** to duplicate the character data. 75 ** 76 ** If a string has multiple references it cannot be changed. Any 77 ** instance to be changed is first copied to a new string. This 78 ** means that any function which can change the character data must 79 ** pass a pointer to the string so that the string can be moved. 80 ** 81 ** A default null string is provided. New strings are by default 82 ** implemented as pointers to this with increased reference counters. 83 ** 84 ** AjPStr is implemented as a pointer to a C data structure. 85 ** 86 ** @alias AjPPStr 87 ** @alias AjSStr 88 ** @alias AjOStr 89 ** @iterator AjIStr 90 ** 91 ** @attr Res [size_t] Reserved bytes (usable for expanding in place) 92 ** @attr Len [size_t] Length of current string, excluding NULL at end 93 ** @attr Ptr [char*] The string, as a NULL-terminated C string. 94 ** @attr Use [ajuint] Use count: 1 for single reference, more if several 95 ** pointers share the same string. 96 ** Must drop to 0 before deleting. Modifying means making 97 ** a new string if not 1. 98 ** @attr Padding [ajint] Padding to alignment boundary 99 ** @@ 100 ******************************************************************************/ 101 102 typedef struct AjSStr 103 { 104 size_t Res; 105 size_t Len; 106 char *Ptr; 107 ajuint Use; 108 ajint Padding; 109 } AjOStr; 110 111 #define AjPStr AjOStr* 112 typedef AjPStr* AjPPStr; 113 114 115 116 117 /* @data AjIStr *************************************************************** 118 ** 119 ** String iterator, used to test iterator functionality. 120 ** 121 ** @alias AjSStrIter 122 ** @alias AjOStrIter 123 ** 124 ** @new ajStrIter Creates and initialises an iterator for a string 125 ** 126 ** @delete ajStrIterFree Destructor for a string iterator 127 ** 128 ** @modify ajStrIterNext Steps to the next iteration 129 ** 130 ** @modify ajStrIterBegin returns result of first iteration 131 ** @modify ajStrIterNext Steps to the next iteration 132 ** @modify ajStrIterBackNext Step to previous character in string iterator. 133 ** @modify ajStrIterEnd returns result of last iteration 134 ** @cast ajStrIterDone Tests whether iteration is complete 135 ** @cast ajStrIterGetC returns the character* from the iterator 136 ** @cast ajStrIterGetK returns the character from the iterator 137 ** 138 ** @attr Start [char*] Starting string pointer 139 ** @attr End [char*] Final string pointer (NULL character position) 140 ** @attr Ptr [char*] Current string pointer 141 ** @@ 142 ******************************************************************************/ 143 144 typedef struct AjSStrIter 145 { 146 char *Start; 147 char *End; 148 char *Ptr; 149 } AjOStrIter; 150 151 #define AjIStr AjOStrIter* 152 153 154 155 156 /* @data AjPStrTok ************************************************************ 157 ** 158 ** String token parser object for the string parsing functions. These normally 159 ** require a set of characters to be skipped, but some functions use a string 160 ** delimiter instead. 161 ** 162 ** @attr String [AjPStr] String 163 ** @attr Delim [AjPStr] Delimiter set for ajStrToken 164 ** @attr Pos [ajuint] Position in string 165 ** @attr Padding [char[4]] Padding to alignment boundary 166 ** 167 ** @new ajStrTokenInit Generates a string token parser object 168 ** @delete ajStrTokenClear Destroys a string token parser 169 ** @@ 170 ******************************************************************************/ 171 172 typedef struct AjSStrTok 173 { 174 AjPStr String; 175 AjPStr Delim; 176 ajuint Pos; 177 char Padding[4]; 178 } AjOStrTok; 179 180 #define AjPStrTok AjOStrTok* 181 182 183 184 185 /* ========================================================================= */ 186 /* =========================== public functions ============================ */ 187 /* ========================================================================= */ 188 189 190 191 192 /* 193 ** Prototype definitions 194 */ 195 196 /* === C character string === */ 197 198 /* constructors */ 199 200 char* ajCharNewC(const char* txt); 201 char* ajCharNewS(const AjPStr thys); 202 char* ajCharNewRes(size_t size); 203 char* ajCharNewResC(const char* txt, size_t size); 204 char* ajCharNewResS(const AjPStr str, size_t size); 205 char* ajCharNewResLenC(const char* txt, size_t size, size_t len); 206 char* ajCharNull(void); 207 208 /* destructors */ 209 210 void ajCharDel(char** Ptxt); 211 212 /* filters */ 213 214 char* ajCharGetfilter(const char *txt); 215 char* ajCharGetfilterCase(const char *txt); 216 char* ajCharGetfilterUpper(const char *txt); 217 char* ajCharGetfilterLower(const char *txt); 218 219 /* formatting */ 220 221 AjBool ajCharFmtLower(char *txt); 222 AjBool ajCharFmtUpper(char *txt); 223 224 /* comparison */ 225 226 AjBool ajCharMatchC(const char* txt1, const char* txt2); 227 AjBool ajCharMatchCaseC(const char* txt1, const char* txt2); 228 AjBool ajCharMatchWildC(const char* txt1, const char* txt2); 229 AjBool ajCharMatchWildS(const char* txt, const AjPStr str); 230 AjBool ajCharMatchWildCaseC(const char* txt1, const char* txt2); 231 AjBool ajCharMatchWildCaseS(const char* txt, const AjPStr str); 232 AjBool ajCharMatchWildNextC(const char* txt1, const char* txt2); 233 AjBool ajCharMatchWildWordC(const char* str, const char* txt); 234 AjBool ajCharMatchWildNextCaseC(const char* txt1, const char* txt2); 235 AjBool ajCharMatchWildWordCaseC(const char* str, const char* txt); 236 AjBool ajCharPrefixC(const char* txt, const char* pref); 237 AjBool ajCharPrefixS(const char* txt, const AjPStr pref); 238 AjBool ajCharPrefixCaseC(const char* txt, const char* pref); 239 AjBool ajCharPrefixCaseS(const char* txt, const AjPStr pref); 240 AjBool ajCharSuffixC(const char* txt, const char* suff); 241 AjBool ajCharSuffixS(const char* txt, const AjPStr suff); 242 AjBool ajCharSuffixCaseC(const char* txt, const char* suff); 243 AjBool ajCharSuffixCaseS(const char* txt, const AjPStr suff); 244 245 /* comparison (sorting) */ 246 247 248 int ajCharCmpCase(const char* txt1, const char* txt2); 249 int ajCharCmpCaseLen(const char* txt1, const char* txt2, size_t len); 250 ajint ajCharCmpWild(const char* txt1, const char* txt2); 251 ajint ajCharCmpWildCase(const char* txt1, const char* txt2); 252 253 /* parsing */ 254 255 AjPStr ajCharParseC(const char* txt, const char* delim); 256 257 /* === AjPStr string === */ 258 259 /* constructors */ 260 261 AjPStr ajStrNew(void); 262 AjPStr ajStrNewC(const char *txt); 263 AjPStr ajStrNewK(char ch); 264 AjPStr ajStrNewS(const AjPStr str); 265 AjPStr ajStrNewRef(AjPStr str); 266 AjPStr ajStrNewRes(size_t size); 267 AjPStr ajStrNewResC(const char *txt, size_t size); 268 AjPStr ajStrNewResS(const AjPStr str, size_t size); 269 AjPStr ajStrNewResLenC(const char *txt, size_t size, size_t len); 270 271 const AjPStr ajStrConstEmpty(void); 272 const AjPStr ajStrConstS(const AjPStr); 273 274 /* destructors */ 275 276 void ajStrDel(AjPStr* Pstr); 277 void ajStrDelarray(AjPStr** PPstr); 278 AjBool ajStrDelStatic(AjPStr* Pstr); 279 280 #define MAJSTRDEL(Pstr) { \ 281 if(*Pstr) \ 282 { \ 283 if((*Pstr)->Use <= 1) ajStrDel(Pstr); \ 284 else {--(*Pstr)->Use;(*Pstr) = NULL;} \ 285 } \ 286 } 287 288 /* assignment */ 289 290 AjBool ajStrAssignC(AjPStr* Pstr, const char* txt); 291 AjBool ajStrAssignK(AjPStr* Pstr, char chr); 292 AjBool ajStrAssignS(AjPStr* Pstr, const AjPStr str); 293 AjBool ajStrAssignClear(AjPStr* Pstr); 294 AjBool ajStrAssignEmptyC(AjPStr* pthis, const char* str); 295 AjBool ajStrAssignEmptyS(AjPStr* pthis, const AjPStr str); 296 AjBool ajStrAssignLenC(AjPStr* Pstr, const char* txt, size_t ilen); 297 AjBool ajStrAssignRef(AjPStr* Pstr, AjPStr refstr); 298 #define MAJSTRASSIGNREF(Pstr,refstr) { \ 299 MAJSTRDEL(Pstr); \ 300 (refstr)->Use++; \ 301 *(Pstr) = (refstr); \ 302 } 303 304 AjBool ajStrAssignResC(AjPStr* Pstr, size_t size, const char* txt); 305 AjBool ajStrAssignResS(AjPStr* Pstr, size_t i, const AjPStr str); 306 AjBool ajStrAssignSubC(AjPStr* Pstr, const char* txt, 307 ajlong pos1, ajlong pos2); 308 AjBool ajStrAssignSubS(AjPStr* Pstr, const AjPStr str, 309 ajlong pos1, ajlong pos2); 310 311 #define MAJSTRASSIGNCLEAR(Pstr) { \ 312 if((*Pstr) && (*Pstr)->Use == 1) \ 313 { \ 314 (*Pstr)->Ptr[0]='\0'; \ 315 (*Pstr)->Len=0; \ 316 } else { \ 317 ajStrAssignClear(Pstr); \ 318 } \ 319 } 320 321 322 323 /* combination */ 324 325 AjBool ajStrAppendC(AjPStr* Pstr, const char* txt); 326 AjBool ajStrAppendK(AjPStr* Pstr, char chr); 327 AjBool ajStrAppendS(AjPStr* Pstr, const AjPStr str); 328 AjBool ajStrAppendCountK(AjPStr* Pstr, char chr, ajulong num); 329 AjBool ajStrAppendLenC(AjPStr* Pstr, const char* txt, size_t len); 330 AjBool ajStrAppendSubC(AjPStr* Pstr, const char* txt, 331 ajlong pos1, ajlong pos2); 332 AjBool ajStrAppendSubS(AjPStr* Pstr, const AjPStr str, 333 ajlong pos1, ajlong pos2); 334 335 AjBool ajStrInsertC(AjPStr* pthis, ajlong pos, const char* str); 336 AjBool ajStrInsertK(AjPStr* pthis, ajlong begin, char insert); 337 AjBool ajStrInsertS(AjPStr* pthis, ajlong pos, const AjPStr str); 338 339 AjBool ajStrJoinC(AjPStr* Pstr, ajlong pos1, 340 const char* txt, ajlong pos2); 341 AjBool ajStrJoinS(AjPStr* Pstr, ajlong pos, 342 const AjPStr str, ajlong posb); 343 AjBool ajStrMaskIdent(AjPStr* Pstr, const AjPStr str, char maskchar); 344 AjBool ajStrMaskRange(AjPStr* Pstr, ajlong begin, ajlong end, 345 char maskchar); 346 AjBool ajStrPasteS(AjPStr* Pstr, ajlong pos, const AjPStr str); 347 AjBool ajStrPasteCountK(AjPStr* Pstr, ajlong pos, char chr, 348 ajulong num); 349 AjBool ajStrPasteMaxC(AjPStr* Pstr, ajlong pos, const char* txt, 350 size_t n); 351 AjBool ajStrPasteMaxS(AjPStr* Pstr, ajlong pos, const AjPStr str, 352 size_t n); 353 354 /* cut */ 355 356 AjBool ajStrCutBraces(AjPStr* Pstr); 357 AjBool ajStrCutComments(AjPStr* Pstr); 358 AjBool ajStrCutCommentsRestpos(AjPStr* Pstr, AjPStr* Prest, size_t* pos); 359 AjBool ajStrCutCommentsStart(AjPStr* Pstr); 360 AjBool ajStrCutEnd(AjPStr* Pstr, size_t len); 361 AjBool ajStrCutRange(AjPStr* Pstr, ajlong pos1, ajlong pos2); 362 AjBool ajStrCutStart(AjPStr* Pstr, size_t len); 363 AjBool ajStrKeepRange(AjPStr* Pstr, ajlong pos1, ajlong pos2); 364 AjBool ajStrKeepSetC(AjPStr* Pstr, const char* txt); 365 AjBool ajStrKeepSetS(AjPStr* Pstr, const AjPStr str); 366 AjBool ajStrKeepSetAlpha(AjPStr* Pstr); 367 AjBool ajStrKeepSetAlphaC(AjPStr* Pstr, const char* txt); 368 AjBool ajStrKeepSetAlphaS(AjPStr* Pstr, const AjPStr str); 369 AjBool ajStrKeepSetAlphaRest(AjPStr* Pstr, AjPStr* Prest); 370 AjBool ajStrKeepSetAlphaRestC(AjPStr* Pstr, const char* txt, 371 AjPStr* Prest); 372 AjBool ajStrKeepSetAlphaRestS(AjPStr* Pstr, const AjPStr str, 373 AjPStr* Prest); 374 AjBool ajStrKeepSetAscii(AjPStr* Pstr, int minchar, int maxchar); 375 AjBool ajStrKeepSetFilter(AjPStr* Pstr, const char* filter); 376 AjBool ajStrQuoteStrip(AjPStr *Pstr); 377 AjBool ajStrQuoteStripAll(AjPStr *Pstr); 378 AjBool ajStrRemoveDupchar(AjPStr* Pstr); 379 AjBool ajStrRemoveGap(AjPStr* thys); 380 AjBool ajStrRemoveGapF(AjPStr* thys, float *Pfloat); 381 AjBool ajStrRemoveHtml(AjPStr* pthis); 382 AjBool ajStrRemoveLastNewline(AjPStr* Pstr); 383 AjBool ajStrRemoveSetC(AjPStr* Pstr, const char *txt); 384 AjBool ajStrRemoveWhite(AjPStr* Pstr); 385 AjBool ajStrRemoveWhiteExcess(AjPStr* Pstr); 386 AjBool ajStrRemoveWhiteSpaces(AjPStr* Pstr); 387 AjBool ajStrRemoveWild(AjPStr* Pstr); 388 AjBool ajStrTrimC(AjPStr* pthis, const char* txt); 389 AjBool ajStrTrimEndC(AjPStr* Pstr, const char* txt); 390 AjBool ajStrTrimStartC(AjPStr* Pstr, const char* txt); 391 AjBool ajStrTrimWhite(AjPStr* Pstr); 392 AjBool ajStrTrimWhiteEnd(AjPStr* Pstr); 393 AjBool ajStrTrimWhiteStart(AjPStr* Pstr); 394 AjBool ajStrTruncateLen(AjPStr* Pstr, size_t len); 395 AjBool ajStrTruncatePos(AjPStr* Pstr, ajlong pos); 396 397 /* substitution */ 398 399 AjBool ajStrExchangeCC(AjPStr* Pstr, const char* txt, const char* txtnew); 400 AjBool ajStrExchangeCS(AjPStr* Pstr, const char* txt, 401 const AjPStr strnew); 402 AjBool ajStrExchangeKK(AjPStr* Pstr, char chr, char chrnew); 403 AjBool ajStrExchangeSC(AjPStr* Pstr, const AjPStr str, 404 const char* txtnew); 405 AjBool ajStrExchangeSS(AjPStr* Pstr, const AjPStr str, 406 const AjPStr strnew); 407 AjBool ajStrExchangePosCC(AjPStr* Pstr, ajlong ipos, const char* txt, 408 const char* txtnew); 409 AjBool ajStrExchangeSetCC(AjPStr* Pstr, const char* txt, 410 const char* newc); 411 AjBool ajStrExchangeSetSS(AjPStr* Pstr, const AjPStr str, 412 const AjPStr strnew); 413 AjBool ajStrExchangeSetRestCK(AjPStr* Pstr, const char* txt, 414 char chr); 415 AjBool ajStrExchangeSetRestSK(AjPStr* Pstr, const AjPStr str, 416 char chr); 417 AjBool ajStrRandom(AjPStr *s); 418 AjBool ajStrReverse(AjPStr* Pstr); 419 420 /* query */ 421 422 ajulong ajStrCalcCountC(const AjPStr str, const char* txt); 423 ajulong ajStrCalcCountK(const AjPStr str, char chr); 424 AjBool ajStrHasParentheses(const AjPStr str); 425 AjBool ajStrIsAlnum(const AjPStr str); 426 AjBool ajStrIsAlpha(const AjPStr str); 427 AjBool ajStrIsBool(const AjPStr str); 428 AjBool ajStrIsCharsetC(const AjPStr str, const char* txt); 429 AjBool ajStrIsCharsetS(const AjPStr str, const AjPStr str2); 430 AjBool ajStrIsCharsetCaseC(const AjPStr str, const char* txt); 431 AjBool ajStrIsCharsetCaseS(const AjPStr str, const AjPStr str2); 432 AjBool ajStrIsDouble(const AjPStr str); 433 AjBool ajStrIsFilter(const AjPStr str, const char* filter); 434 AjBool ajStrIsFloat(const AjPStr str); 435 AjBool ajStrIsHex(const AjPStr str); 436 AjBool ajStrIsInt(const AjPStr str); 437 AjBool ajStrIsLong(const AjPStr str); 438 AjBool ajStrIsLower(const AjPStr str); 439 AjBool ajStrIsNum(const AjPStr str); 440 AjBool ajStrIsUpper(const AjPStr str); 441 AjBool ajStrIsWild(const AjPStr str); 442 AjBool ajStrIsWhite(const AjPStr str); 443 AjBool ajStrIsWord(const AjPStr str); 444 AjBool ajStrWhole(const AjPStr str, ajlong pos1, ajlong pos2); 445 446 /* element retrieval */ 447 448 char ajStrGetAsciiCommon(const AjPStr str); 449 char ajStrGetAsciiHigh(const AjPStr str); 450 char ajStrGetAsciiLow(const AjPStr str); 451 char ajStrGetCharFirst(const AjPStr str); 452 #define MAJSTRGETCHARFIRST(str) ((str)->Ptr[0]) 453 char ajStrGetCharLast(const AjPStr str); 454 #define MAJSTRGETCHARLAST(str) ((str)->Len ? \ 455 (str)->Ptr[(str)->Len-1] : '\0') 456 457 char ajStrGetCharPos(const AjPStr str, ajlong pos); 458 #define MAJSTRGETCHARPOS(str, pos) ((pos) > 0 ? \ 459 (str)->Ptr[(pos)] : \ 460 (str)->Ptr[(str)->Len + (pos)) 461 char* ajStrGetfilter(const AjPStr str); 462 char* ajStrGetfilterCase(const AjPStr str); 463 char* ajStrGetfilterUpper(const AjPStr str); 464 char* ajStrGetfilterLower(const AjPStr str); 465 size_t ajStrGetLen(const AjPStr str); 466 #define MAJSTRGETLEN(str) ((str) ? (str)->Len : 0) 467 const char* ajStrGetPtr(const AjPStr str); 468 #define MAJSTRGETPTR(str) ((str) ? (str)->Ptr : ajCharNull()) 469 size_t ajStrGetRes(const AjPStr str); 470 #define MAJSTRGETRES(str) ((str) ? (str)->Res : 0) 471 size_t ajStrGetRoom(const AjPStr str); 472 ajuint ajStrGetUse(const AjPStr str); 473 #define MAJSTRGETUSE(str) ((str) ? (str)->Use : 0) 474 AjBool ajStrGetValid(const AjPStr thys); 475 476 /* modifiable string retrieval */ 477 478 char* ajStrGetuniquePtr(AjPStr *Pstr); 479 #define MAJSTRGETUNIQUEPTR(Pstr) (((*Pstr)->Use > 1) ? \ 480 ajStrGetuniquePtr(Pstr) : (*Pstr)->Ptr) 481 #define MAJSTRGETUNIQUESTR(Pstr) (((*Pstr)->Use > 1) ? \ 482 ajStrGetuniqueStr(Pstr) : *Pstr) 483 AjPStr ajStrGetuniqueStr(AjPStr *Pstr); 484 485 /* element assignment */ 486 487 AjBool ajStrSetClear(AjPStr* pthis); 488 AjBool ajStrSetRes(AjPStr* Pstr, size_t size); 489 AjBool ajStrSetResRound(AjPStr* Pstr, size_t size); 490 AjBool ajStrSetValid(AjPStr *Pstr); 491 AjBool ajStrSetValidLen(AjPStr* Pstr, size_t len); 492 493 #define MAJSTRSETVALIDLEN(Pstr,len) (*Pstr)->Len = len 494 495 496 497 /* string to datatype conversion functions */ 498 499 AjBool ajStrToBool(const AjPStr str, AjBool* Pval); 500 AjBool ajStrToDouble(const AjPStr str, double* Pval); 501 AjBool ajStrToFloat(const AjPStr str, float* Pval); 502 AjBool ajStrToHex(const AjPStr str, ajint* Pval); 503 AjBool ajStrToInt(const AjPStr str, ajint* Pval); 504 AjBool ajStrToLong(const AjPStr thys, ajlong* result); 505 AjBool ajStrToUint(const AjPStr str, ajuint* Pval); 506 AjBool ajStrToUlong(const AjPStr str, ajulong* Pval); 507 508 /* datatype to string conversion functions */ 509 510 AjBool ajStrFromBool(AjPStr* Pstr, AjBool val); 511 AjBool ajStrFromDouble(AjPStr* Pstr, double val, ajint precision); 512 AjBool ajStrFromDoubleExp(AjPStr* Pstr, double val, ajint precision); 513 AjBool ajStrFromFloat(AjPStr* Pstr, float val, ajint precision); 514 AjBool ajStrFromInt(AjPStr* Pstr, ajint val); 515 AjBool ajStrFromLong(AjPStr* Pstr, ajlong val); 516 AjBool ajStrFromUint(AjPStr* Pstr, ajuint val); 517 AjBool ajStrFromVoid(AjPStr* Pstr, const void* val); 518 519 /* formatting */ 520 521 AjBool ajStrFmtBlock(AjPStr* pthis, ajulong blksize); 522 AjBool ajStrFmtCapital(AjPStr* Pstr); 523 AjBool ajStrFmtLower(AjPStr* Pstr); 524 AjBool ajStrFmtLowerSub(AjPStr* Pstr, ajlong pos1, ajlong pos2); 525 AjBool ajStrFmtPercentDecode(AjPStr* Pstr); 526 AjBool ajStrFmtPercentEncodeC(AjPStr* Pstr, const char* txt); 527 AjBool ajStrFmtPercentEncodeS(AjPStr* Pstr, const AjPStr str); 528 AjBool ajStrFmtQuery(AjPStr* Pstr); 529 AjBool ajStrFmtQuote(AjPStr* Pstr); 530 AjBool ajStrFmtTitle(AjPStr* Pstr); 531 AjBool ajStrFmtUpper(AjPStr* Pstr); 532 AjBool ajStrFmtUpperSub(AjPStr* Pstr, ajlong pos1, ajlong pos2); 533 AjBool ajStrFmtWord(AjPStr* Pstr); 534 AjBool ajStrFmtWrap(AjPStr* Pstr, ajuint width); 535 AjBool ajStrFmtWrapAt(AjPStr* Pstr, ajuint width, char ch); 536 AjBool ajStrFmtWrapLeft(AjPStr* Pstr, ajuint width, 537 ajuint margin, ajuint indent); 538 539 /* comparison */ 540 541 AjBool ajStrMatchC(const AjPStr thys, const char* txt); 542 AjBool ajStrMatchS(const AjPStr thys, const AjPStr str); 543 AjBool ajStrMatchCaseC(const AjPStr thys, const char* text); 544 AjBool ajStrMatchCaseS(const AjPStr thys, const AjPStr str); 545 AjBool ajStrMatchWildC(const AjPStr thys, const char* text); 546 AjBool ajStrMatchWildS(const AjPStr thys, const AjPStr wild); 547 AjBool ajStrMatchWildCaseC(const AjPStr thys, const char* text); 548 AjBool ajStrMatchWildCaseS(const AjPStr thys, const AjPStr wild); 549 AjBool ajStrMatchWildWordC(const AjPStr str, const char* text); 550 AjBool ajStrMatchWildWordS(const AjPStr str, const AjPStr text); 551 AjBool ajStrMatchWildWordCaseC(const AjPStr str, const char* text); 552 AjBool ajStrMatchWildWordCaseS(const AjPStr str, const AjPStr text); 553 AjBool ajStrMatchWordAllS(const AjPStr str, const AjPStr str2); 554 AjBool ajStrMatchWordOneS(const AjPStr str, const AjPStr str2); 555 AjBool ajStrPrefixC(const AjPStr str, const char* txt2); 556 AjBool ajStrPrefixS(const AjPStr str, const AjPStr str2); 557 AjBool ajStrPrefixCaseC(const AjPStr str, const char* pref); 558 AjBool ajStrPrefixCaseS(const AjPStr str, const AjPStr pref); 559 560 AjBool ajStrSuffixC(const AjPStr thys, const char* suff); 561 AjBool ajStrSuffixS(const AjPStr thys, const AjPStr suff); 562 AjBool ajStrSuffixCaseC(const AjPStr str, const char* pref); 563 AjBool ajStrSuffixCaseS(const AjPStr str, const AjPStr pref); 564 565 /* comparison (sorting) */ 566 567 #define MAJSTRCMPC(str1,txt2) strcmp((str1)->Ptr, txt2) 568 #define MAJSTRCMPS(str1,str2) strcmp((str1)->Ptr, (str2)->Ptr) 569 570 int ajStrCmpC(const AjPStr thys, const char *text); 571 int ajStrCmpS(const AjPStr str, const AjPStr str2); 572 int ajStrCmpCaseS(const AjPStr str1, const AjPStr str2); 573 ajint ajStrCmpLenC(const AjPStr thys, const char *text, size_t len); 574 int ajStrCmpLenS(const AjPStr str, const AjPStr str2, size_t len); 575 int ajStrCmpWildC(const AjPStr thys, const char* text); 576 int ajStrCmpWildS(const AjPStr thys, const AjPStr str); 577 int ajStrCmpWildCaseC(const AjPStr thys, const char* text); 578 int ajStrCmpWildCaseS(const AjPStr thys, const AjPStr str); 579 int ajStrVcmp(const void* str1, const void* str2); 580 581 /* comparison (search) */ 582 583 ajlong ajStrFindC(const AjPStr str, const char* txt); 584 ajlong ajStrFindK(const AjPStr str, char chr); 585 ajlong ajStrFindS(const AjPStr str, const AjPStr str2); 586 ajlong ajStrFindAnyC(const AjPStr str, const char* txt); 587 ajlong ajStrFindAnyK(const AjPStr str, char chr); 588 ajlong ajStrFindAnyS(const AjPStr str, const AjPStr str2); 589 ajlong ajStrFindCaseC(const AjPStr str, const char* txt); 590 ajlong ajStrFindCaseS(const AjPStr str, const AjPStr str2); 591 ajlong ajStrFindNextC(const AjPStr str, ajlong pos, const char* txt); 592 ajlong ajStrFindNextK(const AjPStr str, ajlong pos, char chr); 593 ajlong ajStrFindNextS(const AjPStr str, ajlong pos, const AjPStr str2); 594 ajlong ajStrFindRestC(const AjPStr str, const char* txt); 595 ajlong ajStrFindRestS(const AjPStr str, const AjPStr str2); 596 ajlong ajStrFindRestCaseC(const AjPStr str, const char* txt); 597 ajlong ajStrFindRestCaseS(const AjPStr str, const AjPStr str2); 598 ajlong ajStrFindlastC(const AjPStr str, const char* txt); 599 ajlong ajStrFindlastK(const AjPStr str, char chr); 600 ajlong ajStrFindlastS(const AjPStr str, const AjPStr str2); 601 602 /* parsing */ 603 604 AjBool ajStrExtractFirst(const AjPStr str, AjPStr* Prest, AjPStr* Pword); 605 AjBool ajStrExtractToken(const AjPStr str, AjPStr* Prest, AjPStr* Pword); 606 AjBool ajStrExtractWord(const AjPStr str, AjPStr* Prest, AjPStr* Pword); 607 const AjPStr ajStrParseC(const AjPStr str, const char* txtdelim); 608 ajuint ajStrParseCount(const AjPStr line); 609 ajuint ajStrParseCountC(const AjPStr line, const char *txtdelim); 610 ajuint ajStrParseCountS(const AjPStr line, const AjPStr strdelim); 611 ajuint ajStrParseCountMultiC(const AjPStr str, const char *txtdelim); 612 ajuint ajStrParseSplit(const AjPStr str, AjPStr **PPstr); 613 const AjPStr ajStrParseWhite(const AjPStr str); 614 615 /* debug */ 616 617 void ajStrProbe(AjPStr const * Pstr); 618 void ajStrStat(const char* title); 619 void ajStrTrace(const AjPStr thys); 620 void ajStrTraceFull(const AjPStr thys); 621 void ajStrTraceTitle(const AjPStr thys, const char* title); 622 623 /* exit */ 624 625 void ajStrExit(void); 626 627 /* === string iterator === */ 628 629 /* constructors */ 630 631 AjIStr ajStrIterNew(const AjPStr thys); 632 AjIStr ajStrIterNewBack(const AjPStr thys); 633 634 /* destructors */ 635 636 void ajStrIterDel(AjIStr *iter); 637 638 /* tests */ 639 640 AjBool ajStrIterDone(const AjIStr iter); 641 AjBool ajStrIterDoneBack(const AjIStr iter); 642 643 /* resets */ 644 645 void ajStrIterBegin(AjIStr iter); 646 void ajStrIterEnd(AjIStr iter); 647 648 /* attributes */ 649 650 const char* ajStrIterGetC(const AjIStr iter); 651 char ajStrIterGetK(const AjIStr iter); 652 653 /* modifiers */ 654 655 void ajStrIterPutK(AjIStr iter, char chr); 656 657 /* stepping */ 658 659 AjIStr ajStrIterNext(AjIStr iter); 660 AjIStr ajStrIterNextBack(AjIStr iter); 661 662 /* === string token parser === */ 663 664 /* constructors */ 665 666 AjPStrTok ajStrTokenNewC(const AjPStr str, const char* txtdelim); 667 AjPStrTok ajStrTokenNewS(const AjPStr str, const AjPStr strdelim); 668 669 AjPStrTok ajStrTokenNewcharC(const char* txt, const char* txtdelim); 670 AjPStrTok ajStrTokenNewcharS(const char* txt, const AjPStr strdelim); 671 672 /* destructors */ 673 674 void ajStrTokenDel(AjPStrTok* Ptoken); 675 676 /* assignment */ 677 678 AjBool ajStrTokenAssign(AjPStrTok* Ptoken, const AjPStr str); 679 AjBool ajStrTokenAssignC(AjPStrTok* Ptoken, const AjPStr str, 680 const char* txtdelim); 681 AjBool ajStrTokenAssignS(AjPStrTok* Ptoken, const AjPStr str, 682 const AjPStr strdelim); 683 AjBool ajStrTokenAssignchar(AjPStrTok* Ptoken, const char *txt); 684 AjBool ajStrTokenAssigncharC(AjPStrTok* Ptoken, const char *txt, 685 const char* txtdelim); 686 AjBool ajStrTokenAssigncharS(AjPStrTok* Ptoken, const char *txt, 687 const AjPStr strdelim); 688 689 /* reset */ 690 691 void ajStrTokenReset(AjPStrTok token); 692 693 /* debug */ 694 695 void ajStrTokenTrace(const AjPStrTok token); 696 697 /* parsing */ 698 699 AjBool ajStrTokenNextFind(AjPStrTok token, AjPStr* Pstr); 700 AjBool ajStrTokenNextFindC(AjPStrTok token, const char* strdelim, 701 AjPStr* Pstr); 702 AjBool ajStrTokenNextParse(AjPStrTok token, AjPStr* Pstr); 703 AjBool ajStrTokenNextParseC(AjPStrTok token, const char* txtdelim, 704 AjPStr* Pstr); 705 AjBool ajStrTokenNextParseS(AjPStrTok token, const AjPStr strdelim, 706 AjPStr* Pstr); 707 AjBool ajStrTokenNextParseNoskip(AjPStrTok token, AjPStr* Pstr); 708 AjBool ajStrTokenNextParseDelimiters(AjPStrTok token, AjPStr* Pstr, 709 AjPStr* Pdelim); 710 AjBool ajStrTokenRestParse(AjPStrTok token, AjPStr* Pstr); 711 AjBool ajStrTokenStep(AjPStrTok token); 712 AjBool ajStrTokenStepC(AjPStrTok token, const char* txtdelim); 713 AjBool ajStrTokenStepS(AjPStrTok token, const AjPStr strdelim); 714 715 /* 716 ** End of prototype definitions 717 */ 718 719 720 721 722 /*#define MAJSTRREF(str) str->Use*/ 723 /*#define MAJSTRSIZE(str) str->Res*/ 724 /*#define MAJSTRSUBK(str,pos,c) str->Ptr[pos]=c*/ 725 /*#define MAJSTRSTR(str) str->Ptr*/ 726 727 728 #ifdef AJ_COMPILE_DEPRECATED_BOOK 729 #endif /* AJ_COMPILE_DEPRECATED_BOOK */ 730 731 #ifdef AJ_COMPILE_DEPRECATED 732 733 /* ===================================================================== 734 ** Deprecated functions - renamed or replaced 735 ** __deprecated The tag is used by the gcc compiler to report calls 736 ** for other compilers it is defined as an empty string (i.e. removed) 737 ** ===================================================================== */ 738 739 __deprecated void ajCharFree(char** txt); 740 __deprecated char *ajCharNew(const AjPStr thys); 741 __deprecated char *ajCharNewL(size_t size); 742 __deprecated char *ajCharNewLS(size_t size, const AjPStr thys); 743 __deprecated ajint ajCharPos(const char* txt, ajint ipos); 744 __deprecated void ajCharToLower(char *txt); 745 __deprecated void ajCharToUpper(char *txt); 746 747 __deprecated AjBool ajStrApp(AjPStr* pthis, const AjPStr src); 748 __deprecated AjBool ajStrAppC(AjPStr* pthis, const char *txt); 749 __deprecated AjBool ajStrAppCI(AjPStr* pthis, const char *txt, size_t i); 750 __deprecated AjBool ajStrAppK(AjPStr* pthis, const char chr); 751 __deprecated AjBool ajStrAppKI(AjPStr* pthis, const char chr, 752 ajint number); 753 __deprecated AjBool ajStrAppSub(AjPStr* pthis, const AjPStr src, 754 ajint begin, ajint end); 755 __deprecated void ajStrArrayDel(AjPStr** pthis); 756 __deprecated AjBool ajStrAss(AjPStr* pthis, AjPStr str); /* not const */ 757 __deprecated AjBool ajStrAssC(AjPStr* pthis, const char* txt); 758 __deprecated AjBool ajStrAssCI(AjPStr* pthis, const char* txt, size_t i); 759 __deprecated AjBool ajStrAssCL(AjPStr* pthis, const char* txt, size_t i); 760 __deprecated AjBool ajStrAssI(AjPStr* pthis, const AjPStr str, size_t i); 761 __deprecated AjBool ajStrAssK(AjPStr* pthis, const char text); 762 __deprecated AjBool ajStrAssL(AjPStr* pthis, const AjPStr str, size_t i); 763 __deprecated AjBool ajStrAssS(AjPStr* pthis, const AjPStr str); 764 __deprecated AjBool ajStrAssSub(AjPStr* pthis, const AjPStr str, 765 ajint begin, ajint end); 766 __deprecated AjBool ajStrAssSubC(AjPStr* pthis, const char* txt, 767 ajint begin, ajint end); 768 __deprecated AjBool ajStrBlock(AjPStr* pthis, ajint blksize); 769 __deprecated char ajStrChar(const AjPStr thys, ajint pos); 770 __deprecated AjBool ajStrChomp(AjPStr* pthis); 771 __deprecated AjBool ajStrChompC(AjPStr* pthis, const char* delim); 772 __deprecated AjBool ajStrChompEnd(AjPStr* pthis); 773 __deprecated AjBool ajStrChop(AjPStr* pthis); 774 __deprecated AjBool ajStrClean(AjPStr* s); 775 __deprecated AjBool ajStrCleanWhite(AjPStr* s); 776 __deprecated AjBool ajStrClear(AjPStr* pthis); 777 __deprecated int ajStrCmp(const void* str, const void* str2); 778 __deprecated int ajStrCmpCase(const AjPStr str, const AjPStr str2); 779 __deprecated int ajStrCmpCaseCC(const char* str1, const char* str2); 780 __deprecated int ajStrCmpO(const AjPStr thys, const AjPStr anoth); 781 __deprecated int ajStrCmpWild(const AjPStr str, const AjPStr str2); 782 __deprecated int ajStrCmpWildCC(const char* str, const char* text); 783 __deprecated AjBool ajStrConvert(AjPStr* pthis, const AjPStr oldc, 784 const AjPStr newc); 785 __deprecated AjBool ajStrConvertCC(AjPStr* pthis, const char* oldc, 786 const char* newc); 787 __deprecated AjBool ajStrCopy(AjPStr* pthis, AjPStr str); /* not const */ 788 __deprecated AjBool ajStrCopyC(AjPStr* pthis, const char* str); 789 __deprecated ajint ajStrCountC(const AjPStr thys, const char* str); 790 __deprecated ajint ajStrCountK(const AjPStr thys, char ch); 791 __deprecated AjBool ajStrCut(AjPStr* pthis, ajint begin, ajint end); 792 __deprecated void ajStrDegap(AjPStr* pthis); 793 __deprecated AjBool ajStrDelReuse(AjPStr* pthis); 794 __deprecated AjBool ajStrDelim(AjPStr* pthis, AjPStrTok *ptoken, 795 const char *delim); 796 __deprecated AjPStr ajStrDup(AjPStr thys); 797 __deprecated void ajStrFill(AjPStr* pthis, ajint count, char fill); 798 __deprecated ajint ajStrFind(const AjPStr str, const AjPStr str2); 799 __deprecated ajint ajStrFindCase(const AjPStr str, const AjPStr str2); 800 __deprecated ajint ajStrFindK(const AjPStr thys, const char chr); 801 __deprecated void ajStrFix(AjPStr *pthys); 802 __deprecated void ajStrFixI(AjPStr *pthys, ajint ilen); 803 __deprecated AjBool ajStrFromDoubleE(AjPStr* Pstr, double val, 804 ajint precision); 805 __deprecated AjBool ajStrInsert(AjPStr* Pstr, ajint pos, 806 const AjPStr str); 807 __deprecated AjBool ajStrIsSpace(const AjPStr thys); 808 __deprecated AjBool ajStrKeepAlphaC(AjPStr* pthis, const char* chars); 809 __deprecated AjBool ajStrKeepC(AjPStr* pthis, const char* chars); 810 __deprecated ajint ajStrLen(const AjPStr thys); 811 __deprecated ajint ajStrListToArray(const AjPStr str, AjPStr **array); 812 __deprecated AjBool ajStrMask(AjPStr* str, ajint begin, ajint end, 813 char maskchar); 814 __deprecated AjBool ajStrMatchCaseCC(const char* thys, const char* text); 815 __deprecated AjBool ajStrMatchCC(const char* thys, const char* text); 816 __deprecated AjBool ajStrMatchWildCC(const char* str, const char* text); 817 __deprecated AjBool ajStrMatchWildCO(const char* str, const AjPStr wild); 818 __deprecated AjBool ajStrMatchWord(const AjPStr str, const AjPStr text); 819 __deprecated AjBool ajStrMatchWordCC(const char* str, const char* text); 820 __deprecated AjBool ajStrMod(AjPStr* pthis); 821 __deprecated AjBool ajStrModL(AjPStr* pthis, size_t size); 822 __deprecated AjBool ajStrModMinL(AjPStr* pthis, ajuint size); 823 __deprecated AjPStr ajStrNewL(size_t size); 824 __deprecated AjBool ajStrMatch(const AjPStr str, const AjPStr str2); 825 __deprecated AjBool ajStrMatchCase(const AjPStr str, const AjPStr str2); 826 __deprecated AjBool ajStrMatchWild(const AjPStr str, const AjPStr str2); 827 __deprecated int ajStrNCmpC(const AjPStr str, const char* txt, 828 ajint len); 829 __deprecated ajint ajStrNCmpCaseCC(const char* str1, const char* str2, 830 ajint len); 831 __deprecated ajint ajStrNCmpO(const AjPStr thys, const AjPStr anoth, 832 ajint n); 833 __deprecated AjPStr ajStrNewCL(const char *txt, size_t size); 834 __deprecated AjPStr ajStrNewCIL(const char *txt, ajint len, size_t size); 835 __deprecated const AjPStr ajStrNull(void); 836 __deprecated AjBool ajStrParentheses(const AjPStr s); 837 __deprecated ajint ajStrPos(const AjPStr thys, ajint ipos); 838 __deprecated ajint ajStrPosI(const AjPStr thys, ajint imin, ajint ipos); 839 __deprecated ajint ajStrPosII(ajint ilen, ajint imin, ajint ipos); 840 __deprecated AjBool ajStrPrefix(const AjPStr str, const AjPStr str2); 841 __deprecated AjBool ajStrPrefixCase(const AjPStr str, const AjPStr str2); 842 __deprecated AjBool ajStrPrefixCaseCC(const char *str, const char* pref); 843 __deprecated AjBool ajStrPrefixCaseCO(const char* thys, 844 const AjPStr pref); 845 __deprecated AjBool ajStrPrefixCC(const char *str, const char* pref); 846 __deprecated AjBool ajStrPrefixCO(const char *str, const AjPStr thys); 847 __deprecated void ajStrQuote(AjPStr *s); 848 __deprecated AjBool ajStrReplace(AjPStr* pthis, ajint pos1, 849 const AjPStr overwrite, ajint len); 850 __deprecated AjBool ajStrReplaceC(AjPStr* pthis, ajint pos1, 851 const char* overwrite, ajint len); 852 __deprecated AjBool ajStrReplaceK(AjPStr* pthis, ajint pos1, 853 char overwrite, ajint len); 854 __deprecated AjBool ajStrReplaceS(AjPStr* pthis, 855 ajint begin, const AjPStr overwrite); 856 __deprecated ajint ajStrRef(const AjPStr thys); 857 __deprecated void ajStrRemoveCharsC(AjPStr* thys, const char *strng); 858 __deprecated void ajStrRemoveNewline(AjPStr* pthis); 859 __deprecated AjBool ajStrRev(AjPStr* pthis); 860 __deprecated ajint ajStrRFindC(const AjPStr thys, const char *text); 861 __deprecated ajint ajStrRoom(const AjPStr thys); 862 __deprecated AjBool ajStrSet(AjPStr* pthis, const AjPStr str); 863 __deprecated AjBool ajStrSetC(AjPStr* pthis, const char* str); 864 __deprecated ajint ajStrSize(const AjPStr thys); 865 __deprecated const char *ajStrStr(const AjPStr thys); 866 __deprecated char *ajStrStrMod(AjPStr* thys); 867 __deprecated AjBool ajStrSub(AjPStr* pthis, ajint begin, ajint len); 868 __deprecated AjBool ajStrSubstitute(AjPStr* pthis, const AjPStr replace, 869 const AjPStr putin); 870 __deprecated AjBool ajStrSubstituteCC(AjPStr* pthis, const char* replace, 871 const char* putin); 872 __deprecated AjBool ajStrSubstituteKK(AjPStr* pthis, char replace, 873 char putin); 874 __deprecated AjBool ajStrSuffix(const AjPStr str, const AjPStr str2); 875 __deprecated AjBool ajStrSuffixCC(const char *str, const char* suff); 876 __deprecated AjBool ajStrSuffixCO(const char *str, const AjPStr suff); 877 __deprecated AjBool ajStrToLower(AjPStr* pthis); 878 __deprecated AjBool ajStrToLowerII(AjPStr* pthis, ajint begin, ajint end); 879 __deprecated AjBool ajStrToTitle(AjPStr* pthis); 880 __deprecated AjBool ajStrToUpper(AjPStr* pthis); 881 __deprecated AjBool ajStrToUpperII(AjPStr* pthis, ajint begin, ajint end); 882 __deprecated AjBool ajStrTrim(AjPStr* pthis, ajint num); 883 __deprecated AjBool ajStrTruncate(AjPStr* Pstr, ajint pos); 884 __deprecated AjBool ajStrUncomment(AjPStr* text); 885 __deprecated AjBool ajStrUncommentStart(AjPStr* text); 886 __deprecated AjBool ajStrWildPrefix(AjPStr* str); 887 __deprecated AjBool ajStrWrap(AjPStr* pthis, ajint width); 888 __deprecated AjBool ajStrWrapLeft(AjPStr* pthis, ajint width, 889 ajint left); 890 891 892 893 894 __deprecated AjIStr ajStrIter(const AjPStr thys); 895 __deprecated AjIStr ajStrIterBack(const AjPStr thys); 896 __deprecated AjBool ajStrIterBackDone(AjIStr iter); 897 __deprecated AjIStr ajStrIterBackNext(AjIStr iter); 898 __deprecated void ajStrIterFree(AjIStr *iter); 899 __deprecated AjBool ajStrIterMore(AjIStr iter); 900 __deprecated AjBool ajStrIterMoreBack(AjIStr iter); 901 902 903 __deprecated const AjPStr ajStrTok(const AjPStr thys); 904 __deprecated const AjPStr ajStrTokC(const AjPStr thys, const char* delim); 905 __deprecated const AjPStr ajStrTokCC(const char* thys, const char* delim); 906 __deprecated AjBool ajStrToken(AjPStr* pthis, AjPStrTok *ptoken, 907 const char *delim); 908 __deprecated AjBool ajStrTokenAss(AjPStrTok *ptok, const AjPStr thys, 909 const char *delim); 910 __deprecated void ajStrTokenClear(AjPStrTok *token); 911 __deprecated ajint ajStrTokenCount(const AjPStr line, const char *delim); 912 __deprecated ajint ajStrTokenCountR(const AjPStr line, const char *delim); 913 __deprecated AjPStrTok ajStrTokenInit(const AjPStr thys, const char *delim); 914 __deprecated AjBool ajStrTokenRest(AjPStr* pthis, AjPStrTok* ptoken); 915 916 /*#define MAJSTRLEN(str) str->Len*/ 917 __deprecated const char *MAJSTRSTR(const AjPStr thys); 918 __deprecated ajint MAJSTRLEN(const AjPStr thys); 919 __deprecated ajint MAJSTRSIZE(const AjPStr thys); 920 __deprecated ajint MAJSTRREF(const AjPStr thys); 921 922 #endif /* AJ_COMPILE_DEPRECATED */ 923 924 925 926 927 AJ_END_DECLS 928 929 #endif /* !AJSTR_H */ 930