00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 const char *XrdOucStringCVSID = "$Id: XrdOucString.cc 31975 2010-01-07 14:38:29Z ganis $";
00012
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <climits>
00016
00017 #include <XrdOuc/XrdOucString.hh>
00018
00019
00020
00021
00022
00023
00024
00025 #define kMAXINT64LEN 25
00026
00027 #if !defined(WINDOWS)
00028
00029
00030 #define XOSINTFORM(f,b) \
00031 int buf_len = 256; \
00032 va_list ap; \
00033 va_start(ap, f); \
00034 again: \
00035 b = (char *)realloc(b, buf_len); \
00036 int n = vsnprintf(b, buf_len, f, ap); \
00037 if (n == -1 || n >= buf_len) { \
00038 if (n == -1) \
00039 buf_len *= 2; \
00040 else \
00041 buf_len = n+1; \
00042 va_end(ap); \
00043 va_start(ap, f); \
00044 goto again; \
00045 } \
00046 va_end(ap);
00047
00048 #endif
00049
00050
00051
00052 int XrdOucString::blksize = -1;
00053
00054
00055 int XrdOucString::adjust(int ls, int &j, int &k, int nmx)
00056 {
00057
00058
00059
00060
00061
00062 j = (j < 0) ? 0 : j;
00063
00064 k = (k == -1 || k > (ls-1)) ? (ls-1) : k;
00065
00066 int nlen = k - j + 1;
00067 nlen = (nlen > 0) ? nlen : 0;
00068
00069 if (nmx > 0 && nmx < nlen) {
00070 k = j + 1 + nmx;
00071 nlen = nmx;
00072 }
00073
00074 return nlen;
00075 }
00076
00077
00078 char *XrdOucString::bufalloc(int nsz)
00079 {
00080
00081
00082
00083
00084
00085
00086
00087 char *nstr = 0;
00088
00089
00090 if (nsz <= 0) {
00091 if (str) free(str);
00092 init();
00093 return nstr;
00094 }
00095
00096 int sz = nsz;
00097
00098 if (blksize > 1) {
00099 int blks = nsz / blksize;
00100 sz = (blks+1) * blksize;
00101 }
00102
00103
00104 if (sz != siz) {
00105 if ((nstr = (char *)realloc(str, sz)))
00106 siz = sz;
00107 } else
00108
00109 nstr = str;
00110
00111
00112 return nstr;
00113 }
00114
00115
00116 XrdOucString::XrdOucString(const char c, int ls)
00117 {
00118
00119
00120
00121
00122 init();
00123
00124
00125 if (ls > 0)
00126 str = bufalloc(ls+1);
00127 else
00128 str = bufalloc(2);
00129 if (str) {
00130 str[0] = c;
00131 str[1] = 0;
00132 len = 1;
00133 }
00134 }
00135
00136
00137 XrdOucString::XrdOucString(const char *s, int ls)
00138 {
00139
00140
00141
00142
00143
00144
00145
00146 init();
00147
00148
00149 if (ls > 0)
00150 str = bufalloc(ls+1);
00151 int lr = s ? strlen(s) : 0;
00152 if (lr >= 0)
00153 assign(s,0,ls-1);
00154 }
00155
00156
00157 XrdOucString::XrdOucString(const XrdOucString &s)
00158 {
00159
00160
00161 init();
00162 assign(s.c_str(),0,-1);
00163 }
00164
00165
00166 XrdOucString::XrdOucString(const XrdOucString &s, int j, int k, int ls)
00167 {
00168
00169
00170 init();
00171
00172 if (ls > 0)
00173 str = bufalloc(ls+1);
00174
00175 int lr = s.length();
00176 if (lr > 0) {
00177
00178 if (adjust(lr, j, k, ls) > 0)
00179
00180 assign(s.c_str(),j,k);
00181 }
00182 }
00183
00184
00185 XrdOucString::~XrdOucString()
00186 {
00187
00188
00189 if (str) free(str);
00190 }
00191
00192
00193 void XrdOucString::setbuffer(char *buf)
00194 {
00195
00196
00197 if (str) free(str);
00198 init();
00199 if (buf) {
00200 str = buf;
00201 len = strlen(buf);
00202 siz = len + 1;
00203 str = (char *)realloc(str, siz);
00204 }
00205 }
00206
00207 #if !defined(WINDOWS)
00208
00209 int XrdOucString::form(const char *fmt, ...)
00210 {
00211
00212
00213
00214
00215 XOSINTFORM(fmt, str);
00216 siz = buf_len;
00217
00218
00219 len = strlen(str);
00220 str = bufalloc(len+1);
00221
00222
00223 return n;
00224 }
00225
00226
00227 int XrdOucString::form(XrdOucString &str, const char *fmt, ...)
00228 {
00229
00230
00231
00232 char *buf = 0;
00233 XOSINTFORM(fmt, buf);
00234
00235
00236 str.setbuffer(buf);
00237
00238
00239 return n;
00240 }
00241 #endif
00242
00243
00244 int XrdOucString::find(const char c, int start, bool forward)
00245 {
00246
00247
00248
00249 int rc = STR_NPOS;
00250
00251
00252 if (start == STR_NPOS)
00253 start = len - 1;
00254
00255
00256 if (start < 0 || start > (len-1))
00257 return rc;
00258
00259
00260 int i = start;
00261 if (forward) {
00262
00263 for (; i < len; i++) {
00264 if (str[i] == c)
00265 return i;
00266 }
00267 } else {
00268
00269 for (; i >= 0; i--) {
00270 if (str[i] == c)
00271 return i;
00272 }
00273 }
00274
00275
00276 return rc;
00277 }
00278
00279
00280 int XrdOucString::find(XrdOucString s, int start)
00281 {
00282
00283
00284
00285
00286 return find((const char *)s.c_str(),start);
00287 }
00288
00289
00290 int XrdOucString::find(const char *s, int start)
00291 {
00292
00293
00294
00295
00296 int rc = STR_NPOS;
00297
00298
00299 if (start < 0 || start > (len-1))
00300 return rc;
00301
00302
00303 if (!s)
00304 return rc;
00305
00306
00307 int ls = strlen(s);
00308
00309
00310 if (ls == 1)
00311 return find(s[0],start);
00312
00313
00314 if (ls > (len-start))
00315 return rc;
00316
00317
00318 int i = start;
00319 for (; i < len; i++) {
00320 if (str[i] == s[0])
00321 if (!strncmp(str+i+1,s+1,ls-1))
00322 return i;
00323 }
00324
00325
00326 return rc;
00327 }
00328
00329
00330 int XrdOucString::rfind(XrdOucString s, int start)
00331 {
00332
00333
00334
00335
00336
00337 return rfind(s.c_str(),start);
00338 }
00339
00340
00341 int XrdOucString::rfind(const char *s, int start)
00342 {
00343
00344
00345
00346
00347
00348 int rc = STR_NPOS;
00349
00350
00351 if (start == STR_NPOS)
00352 start = len - 1;
00353
00354
00355 if (start < 0 || start > (len-1))
00356 return rc;
00357
00358
00359 if (!s)
00360 return rc;
00361
00362
00363 int ls = strlen(s);
00364
00365
00366 if (ls == 1)
00367 return find(s[0],start,0);
00368
00369
00370 if (ls > len)
00371 return rc;
00372
00373
00374 if (ls > (len-start))
00375 start = len-ls;
00376
00377
00378 int i = start;
00379 for (; i >= 0; i--) {
00380 if (str[i] == s[0])
00381 if (!strncmp(str+i+1,s+1,ls-1))
00382 return i;
00383 }
00384
00385
00386 return rc;
00387 }
00388
00389
00390 bool XrdOucString::endswith(char c)
00391 {
00392
00393
00394 return (rfind(c) == (int)(len-1));
00395 }
00396
00397
00398 bool XrdOucString::endswith(const char *s)
00399 {
00400
00401
00402 return (s ? (rfind(s) == (int)(len-strlen(s))) : 0);
00403 }
00404
00405
00406 int XrdOucString::matches(const char *s, char wch)
00407 {
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417 if (!s || !str)
00418 return 0;
00419
00420
00421 int ls = strlen(s);
00422
00423
00424 if (!strchr(s,wch)) {
00425 if (!strcmp(str,s))
00426 return ls;
00427 else
00428 return 0;
00429 }
00430
00431
00432 if (ls == 1)
00433 return 1;
00434
00435 int rc = 1;
00436
00437 int cs = 0;
00438
00439
00440 int tb = 0;
00441 char *ps = (char *)strchr(s+tb,wch);
00442 bool next = 1;
00443 while (next) {
00444
00445
00446 int te = ps ? (ps - s) : ls;
00447
00448 int ts = te - tb;
00449
00450 if (ts) {
00451 bool found = 0;
00452 while (cs < len) {
00453 if (!strncmp(str+cs,s+tb,ts)) {
00454 cs += ts;
00455 found = 1;
00456 break;
00457 }
00458 cs++;
00459 }
00460 if (!found) {
00461 rc = 0;
00462 break;
00463 }
00464 }
00465
00466 tb = te + 1;
00467 ps = (tb < ls) ? (char *)strchr(s+tb, wch) : 0;
00468 next = (ps || (tb < ls)) ? 1 : 0;
00469 }
00470
00471
00472
00473 if (s[ls-1] != wch && cs < len)
00474 rc = 0;
00475
00476
00477
00478 int nm = 0;
00479 if (rc > 0) {
00480 nm = ls;
00481 int n = ls;
00482 while (n--) {
00483 if (s[n] == wch) nm--;
00484 }
00485 }
00486
00487 return nm;
00488 }
00489
00490
00491 void XrdOucString::assign(const char *s, int j, int k)
00492 {
00493
00494
00495
00496
00497 int ls = s ? strlen(s) : 0;
00498 if (!s) {
00499
00500 if (str) {
00501
00502 str[0] = 0;
00503 len = 0;
00504 }
00505 } else {
00506
00507 int nlen = adjust(ls, j, k);
00508
00509 if (nlen > (siz-1))
00510 str = bufalloc(nlen+1);
00511 if (str) {
00512 if (nlen > 0) {
00513 strncpy(str,s+j,nlen);
00514 str[nlen] = 0;
00515 len = nlen;
00516 } else {
00517
00518 str[0] = 0;
00519 len = 0;
00520 }
00521 }
00522 }
00523 }
00524
00525
00526 void XrdOucString::assign(const XrdOucString s, int j, int k)
00527 {
00528
00529
00530 assign(s.c_str(),j,k);
00531 }
00532
00533
00534 int XrdOucString::keep(int start, int size)
00535 {
00536
00537
00538
00539
00540 int rc = 0;
00541
00542
00543 int st = start;
00544 if (st < 0 || st > (len-1))
00545 return rc;
00546
00547
00548 if (size < 0)
00549 return rc;
00550 int nlen = 0;
00551 if (size == 0) {
00552 nlen = len - st;
00553 } else {
00554 nlen = (size > (len - st)) ? (len - st) : size;
00555 }
00556
00557
00558 if (nlen >= len)
00559 return len;
00560
00561
00562 if (nlen > (siz-1))
00563 str = bufalloc(nlen+1);
00564 if (str) {
00565
00566 memmove(str,str+st,nlen);
00567
00568 str[nlen] = 0;
00569
00570 len = nlen;
00571
00572 return nlen;
00573 } else
00574 return rc;
00575 }
00576
00577
00578 void XrdOucString::append(const char *s)
00579 {
00580
00581
00582
00583 return insert(s);
00584 }
00585
00586
00587 void XrdOucString::append(const XrdOucString s)
00588 {
00589
00590
00591
00592 return insert(s);
00593 }
00594
00595
00596 void XrdOucString::append(const char c)
00597 {
00598
00599
00600
00601 return insert(c);
00602 }
00603
00604
00605 void XrdOucString::append(const int i)
00606 {
00607
00608
00609 return insert(i);
00610 }
00611
00612
00613 void XrdOucString::insert(const char *s, int start, int ls)
00614 {
00615
00616
00617
00618
00619
00620
00621 int at = start;
00622 at = (at < 0 || at > len) ? len : at;
00623
00624 if (s) {
00625 int lstr = (ls > 0) ? ls : strlen(s);
00626 if (str) {
00627 int lnew = len + lstr;
00628 if (lnew > (siz-1))
00629 str = bufalloc(lnew+1);
00630 if (str) {
00631
00632 if (at < len)
00633 memmove(str+at+lstr,str+at,(len-at));
00634
00635 memcpy(str+at,s,lstr);
00636
00637 str[lnew] = 0;
00638 len = lnew;
00639 }
00640 } else {
00641 if ((str = bufalloc(lstr+1))) {
00642 strncpy(str,s,lstr);
00643 str[lstr] = 0;
00644 len = lstr;
00645 }
00646 }
00647 }
00648 }
00649
00650
00651 void XrdOucString::insert(const XrdOucString s, int start)
00652 {
00653
00654
00655
00656 return insert(s.c_str(), start);
00657 }
00658
00659
00660 void XrdOucString::insert(const char c, int start)
00661 {
00662
00663
00664
00665 char sc[2] = {0};
00666 sc[0] = c;
00667 return insert((const char *)&sc[0], start);
00668 }
00669
00670
00671 void XrdOucString::insert(const int i, int start)
00672 {
00673
00674
00675
00676 char si[kMAXINT64LEN] = {0};
00677 sprintf(si,"%d",i);
00678 return insert((const char *)&si[0], start);
00679 }
00680
00681
00682 int XrdOucString::replace(const XrdOucString s1, const char *s2, int from, int to)
00683 {
00684
00685
00686
00687
00688 return replace(s1.c_str(),s2,from,to);
00689 }
00690
00691
00692 int XrdOucString::replace(const char *s1, const XrdOucString s2, int from, int to)
00693 {
00694
00695
00696
00697
00698 return replace(s1,s2.c_str(),from,to);
00699 }
00700
00701
00702 int XrdOucString::replace(const XrdOucString s1,
00703 const XrdOucString s2, int from, int to)
00704 {
00705
00706
00707
00708
00709 return replace(s1.c_str(),s2.c_str(),from,to);
00710 }
00711
00712
00713 int XrdOucString::replace(const char *s1, const char *s2, int from, int to)
00714 {
00715
00716
00717
00718
00719
00720 if (!str || len <= 0)
00721 return 0;
00722
00723
00724 int l1 = s1 ? strlen(s1) : 0;
00725 if (l1 <= 0)
00726 return 0;
00727
00728
00729 if (adjust(len,from,to) <= 0)
00730 return 0;
00731
00732
00733 int l2 = s2 ? strlen(s2) : 0;
00734
00735
00736 int nr = 0;
00737 if (l1 < l2) {
00738 int at = find(s1,from);
00739 while (at > -1 && at <= (to-l1+1)) {
00740 nr++;
00741 at = find(s1,at+l1);
00742 }
00743 }
00744
00745
00746 int nlen = (nr > 0) ? (len + nr*(l2-l1)) : len ;
00747
00748
00749 if (nlen > (siz-1))
00750 str = bufalloc(nlen+1);
00751
00752
00753 int dd = l2-l1;
00754 int dl = 0;
00755 if (str) {
00756 if (dd < 0) {
00757 int nc = 0;
00758 int at = find(s1,from);
00759 while (at > -1 && at <= (to-l1+1)) {
00760 int atn = find(s1,at+l1);
00761 atn = (atn == -1 || atn > (to-l1+1)) ? len : atn;
00762 int ln = atn - at - l1;
00763 char *pc = str+at+nc*dd;
00764 if (l2 > 0)
00765 memcpy(pc,s2,l2);
00766 if (ln > 0)
00767 memmove(pc+l2,str+at+l1,ln);
00768 nc++;
00769 at = atn;
00770 }
00771 dl = nc*dd;
00772 } else if (dd == 0) {
00773 int at = find(s1,from);
00774 while (at > -1 && at <= (to-l1+1)) {
00775 memcpy(str+at,s2,l2);
00776 at = find(s1,at+l1);
00777 }
00778 } else if (dd > 0) {
00779 int nc = nr;
00780 int at = rfind(s1,to);
00781 int atn = len;
00782 while (at > -1 && at >= from) {
00783 int ln = atn - at - l1;
00784 char *pc = str + at + l1 + nc*dd;
00785 if (ln > 0)
00786 memmove(pc,str+at+l1,ln);
00787 if (l2 > 0)
00788 memcpy(pc-l2,s2,l2);
00789 nc--;
00790 atn = at;
00791 at = rfind(s1,at-l1);
00792 }
00793 dl = nr*dd;
00794 }
00795 }
00796
00797
00798 len += dl;
00799
00800 str[len] = 0;
00801
00802 return dl;
00803 }
00804
00805
00806 int XrdOucString::erase(int start, int size)
00807 {
00808
00809
00810
00811
00812 int rc = 0;
00813
00814
00815 int st = start;
00816 if (st < 0 || st > (len-1))
00817 return rc;
00818
00819
00820 if (size < 0)
00821 return rc;
00822 int nrem = 0;
00823 if (size == 0) {
00824 nrem = len - st;
00825 } else {
00826 nrem = (size > (len-st)) ? (len-st) : size;
00827 }
00828
00829 if (nrem <= 0)
00830 return rc;
00831
00832 int nlen = len - nrem;
00833
00834 if (len-st-nrem)
00835 memmove(str+st,str+st+nrem,len-st-nrem);
00836
00837 str[nlen] = 0;
00838
00839 len = nlen;
00840
00841 return nrem;
00842 }
00843
00844
00845 int XrdOucString::erase(const char *s, int from, int to)
00846 {
00847
00848
00849
00850
00851 return -replace(s,0,from,to);
00852 }
00853
00854
00855 int XrdOucString::erase(XrdOucString s, int from, int to)
00856 {
00857
00858
00859
00860
00861 return -replace(s.c_str(),0,from,to);
00862 }
00863
00864
00865 void XrdOucString::lower(int start, int size)
00866 {
00867
00868
00869
00870
00871 int st = start;
00872 if (st < 0 || st > (len-1))
00873 return;
00874
00875
00876 if (size < 0)
00877 return;
00878 int nlw = 0;
00879 if (size == 0) {
00880 nlw = len - st;
00881 } else {
00882 nlw = (size > (len-st)) ? (len-st) : size;
00883 }
00884
00885
00886 if (nlw <= 0)
00887 return;
00888
00889
00890 int i = st;
00891 for (; i < st + nlw ; i++ ) {
00892 if (str[i] > 0x40 && str[i] < 0x5b)
00893 str[i] += 0x20;
00894 }
00895 }
00896
00897
00898 void XrdOucString::upper(int start, int size)
00899 {
00900
00901
00902
00903
00904 int st = start;
00905 if (st < 0 || st > (len-1))
00906 return;
00907
00908
00909 if (size < 0)
00910 return;
00911 int nup = 0;
00912 if (size == 0) {
00913 nup = len - st;
00914 } else {
00915 nup = (size > (len-st)) ? (len-st) : size;
00916 }
00917
00918
00919 if (nup <= 0)
00920 return;
00921
00922
00923 int i = st;
00924 for (; i < st + nup ; i++ ) {
00925 if (str[i] > 0x60 && str[i] < 0x7b)
00926 str[i] -= 0x20;
00927 }
00928 }
00929
00930
00931 void XrdOucString::hardreset()
00932 {
00933
00934
00935 if (str) {
00936 volatile char *buf = 0;
00937 for (buf = (volatile char *)str; len; buf[--len] = 0);
00938 len = 0;
00939 }
00940 len = 0;
00941 }
00942
00943
00944 void XrdOucString::reset(const char c, int j, int k)
00945 {
00946
00947
00948 j = (j >= 0 && j < siz) ? j : 0;
00949 k = (k >= j && k < siz) ? k : siz-1;
00950
00951 if (str) {
00952 volatile char *buf = (volatile char *)str;
00953 int i = j;
00954 for (; i <= k; i++)
00955 buf[i] = c;
00956 }
00957 while (str[len-1] == 0)
00958 --len;
00959 }
00960
00961
00962 XrdOucString& XrdOucString::operator=(const int i)
00963 {
00964
00965
00966 char s[kMAXINT64LEN] = {0};
00967 sprintf(s,"%d",i);
00968 assign((const char *)&s[0],0,-1);
00969 return *this;
00970 }
00971
00972
00973 XrdOucString& XrdOucString::operator=(const char c)
00974 {
00975
00976
00977 const char s[] = {c,0};
00978 assign(s,0,-1);
00979 return *this;
00980 }
00981
00982
00983 XrdOucString& XrdOucString::operator=(const char *s)
00984 {
00985
00986
00987 assign(s,0,-1);
00988
00989 return *this;
00990 }
00991
00992
00993 XrdOucString& XrdOucString::operator=(const XrdOucString s)
00994 {
00995
00996 assign(s.c_str(), 0, -1);
00997
00998 return *this;
00999 }
01000
01001
01002 char &XrdOucString::operator[](int i)
01003 {
01004
01005 static char c = '\0';
01006
01007 if (str) {
01008 if (i > -1 && i < len)
01009 return str[i];
01010 else
01011 abort();
01012 }
01013 return c;
01014 }
01015
01016
01017 XrdOucString operator+(const XrdOucString &s1, const char *s)
01018 {
01019
01020
01021 XrdOucString ns(s1);
01022 if (s && strlen(s))
01023 ns.append(s);
01024 return ns;
01025 }
01026
01027
01028 XrdOucString operator+(const XrdOucString &s1, const XrdOucString &s)
01029 {
01030
01031
01032 XrdOucString ns(s1);
01033 if (s.length())
01034 ns.append(s);
01035 return ns;
01036 }
01037
01038
01039 XrdOucString operator+(const XrdOucString &s1, const char c)
01040 {
01041
01042
01043
01044 XrdOucString ns(s1);
01045 ns.append(c);
01046 return ns;
01047 }
01048
01049
01050 XrdOucString operator+(const XrdOucString &s1, const int i)
01051 {
01052
01053
01054
01055 XrdOucString ns(s1);
01056 ns.append(i);
01057 return ns;
01058 }
01059
01060
01061 XrdOucString& XrdOucString::operator+=(const char *s)
01062 {
01063
01064
01065 if (s && strlen(s))
01066 this->append(s);
01067 return *this;
01068 }
01069
01070
01071 XrdOucString& XrdOucString::operator+=(const XrdOucString s)
01072 {
01073
01074
01075 if (s.length())
01076 this->append(s);
01077 return *this;
01078 }
01079
01080
01081 XrdOucString& XrdOucString::operator+=(const char c)
01082 {
01083
01084
01085 this->append(c);
01086 return *this;
01087 }
01088
01089
01090 XrdOucString& XrdOucString::operator+=(const int i)
01091 {
01092
01093
01094 this->append(i);
01095 return *this;
01096 }
01097
01098
01099
01100 int XrdOucString::operator==(const char *s)
01101 {
01102
01103
01104 if (s && (strlen(s) == (unsigned int)len))
01105 if (!strncmp(str,s,len))
01106 return 1;
01107 return 0;
01108 }
01109
01110
01111 int XrdOucString::operator==(const XrdOucString s)
01112 {
01113
01114
01115 if (s.length() == len)
01116 if (!strncmp(str,s.c_str(),len))
01117 return 1;
01118 return 0;
01119 }
01120
01121
01122 int XrdOucString::operator==(const char c)
01123 {
01124
01125
01126 if (len == 1) {
01127 if (str[0] == c)
01128 return 1;
01129 }
01130 return 0;
01131 }
01132
01133
01134 int XrdOucString::operator==(const int i)
01135 {
01136
01137
01138
01139 char s[kMAXINT64LEN] = {0};
01140 sprintf(s,"%d",i);
01141 return (*this == ((const char *)&s[0]));
01142 }
01143
01144
01145 ostream &operator<< (ostream &os, const XrdOucString s)
01146 {
01147
01148
01149 if (s.c_str())
01150 os << s.c_str();
01151 else
01152 os << "";
01153 return os;
01154 }
01155
01156
01157 XrdOucString const operator+(const char *s1, const XrdOucString s2)
01158 {
01159
01160 XrdOucString res(s1,s2.length()+strlen(s1));
01161 res.insert(s2);
01162 return res;
01163 }
01164
01165
01166 XrdOucString const operator+(const char c, const XrdOucString s)
01167 {
01168
01169 XrdOucString res(c,s.length()+1);
01170 res.insert(s);
01171 return res;
01172 }
01173
01174
01175 XrdOucString const operator+(const int i, const XrdOucString s)
01176 {
01177
01178 XrdOucString res(s.length()+kMAXINT64LEN);
01179 res.insert(i);
01180 res.insert(s);
01181 return res;
01182 }
01183
01184
01185 int XrdOucString::getblksize()
01186 {
01187
01188
01189 return XrdOucString::blksize;
01190 }
01191
01192
01193 void XrdOucString::setblksize(int bs)
01194 {
01195
01196
01197 XrdOucString::blksize = bs;
01198 }
01199
01200
01201 int XrdOucString::tokenize(XrdOucString &tok, int from, char del)
01202 {
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224 if (len <= 0 || from < 0 || from > (len-1))
01225 return -1;
01226
01227
01228 int pos = find(del, from);
01229
01230
01231 if (pos == -1 || pos > from) {
01232 int last = (pos > 0) ? (pos - 1) : -1;
01233 tok.assign(str, from, last);
01234 } else
01235 tok = "";
01236
01237 int next = pos + 1;
01238 if (pos == -1) {
01239 if (tok.length() > 0)
01240
01241 next = len;
01242 else
01243 next = pos;
01244 }
01245
01246
01247 return next;
01248 }
01249
01250
01251 bool XrdOucString::isdigit(int from, int to)
01252 {
01253
01254
01255
01256 if (len <= 0) return 0;
01257
01258
01259 if (from < 0 || from > (len-1)) from = 0;
01260 if (to < from) to = len - 1;
01261
01262 char *c = str + from;
01263
01264
01265 if (*c == '-') c++;
01266
01267 while (c <= str + to) {
01268 if (*c < 48 || *c > 57) return 0;
01269 c++;
01270 }
01271
01272 return 1;
01273 }
01274
01275
01276 long XrdOucString::atoi(int from, int to)
01277 {
01278
01279
01280
01281
01282 if (!isdigit(from, to)) return LONG_MAX;
01283
01284
01285 if (from < 0 || from > (len-1)) from = 0;
01286 if (to < from) to = len - 1;
01287
01288
01289 char e = str[to+1];
01290 str[to+1] = '\0';
01291 long out = strtol(&str[from], 0, 10);
01292 str[to+1] = e;
01293 return out;
01294 }