41 #define kMAXINT64LEN 25
46 #define XOSINTFORM(f,b) \
51 b = (char *)realloc(b, buf_len); \
52 int n = vsnprintf(b, buf_len, f, ap); \
53 if (n == -1 || n >= buf_len) { \
68 int XrdOucString::blksize = -1;
71 int XrdOucString::adjust(
int ls,
int &j,
int &k,
int nmx)
80 k = (k == -1 || k > (ls-1)) ? (ls-1) : k;
83 nlen = (nlen > 0) ? nlen : 0;
85 if (nmx > 0 && nmx < nlen) {
94 char *XrdOucString::bufalloc(
int nsz)
115 int blks = nsz / blksize;
116 sz = (blks+1) * blksize;
121 if ((nstr = (
char *)realloc(str, sz)))
142 str = bufalloc(ls+1);
166 str = bufalloc(ls+1);
167 int lr = s ? strlen(s) : 0;
189 str = bufalloc(ls+1);
194 if (adjust(lr, j, k, ls) > 0)
219 str = (
char *)realloc(str, siz);
223 #if !defined(WINDOWS)
236 str = bufalloc(len+1);
272 if (start < 0 || start > (len-1))
279 for (; i < len; i++) {
285 for (; i >= 0; i--) {
302 return find((
const char *)s.
c_str(),start);
315 if (start < 0 || start > (len-1))
327 return find(s[0],start);
330 if (ls > (len-start))
335 for (; i < len; i++) {
337 if (!strncmp(str+i+1,s+1,ls-1))
371 if (start < 0 || start > (len-1))
383 return find(s[0],start,0);
390 if (ls > (len-start))
395 for (; i >= 0; i--) {
397 if (!strncmp(str+i+1,s+1,ls-1))
410 return ((len > 0) ? (
rfind(c) == (
int)(len-1)) : 0);
419 if (s && (ls = (
int)strlen(s)) <= len)
420 return ((
rfind(s) == (
int)(len-strlen(s))) ? 1 : 0);
444 if (!strchr(s,wch)) {
461 char *ps = (
char *)strchr(s+tb,wch);
466 int te = ps ? (ps - s) : ls;
473 if (!strncmp(str+cs,s+tb,ts)) {
487 ps = (tb < ls) ? (
char *)strchr(s+tb, wch) : 0;
488 next = (ps || (tb < ls)) ? 1 : 0;
493 if (s[ls-1] != wch && cs < len)
503 if (s[n] == wch) nm--;
517 int ls = s ? strlen(s) : 0;
527 int nlen = adjust(ls, j, k);
530 str = bufalloc(nlen+1);
533 strncpy(str,s+j,nlen);
564 if (st < 0 || st > (len-1))
574 nlen = (size > (len - st)) ? (len - st) : size;
583 str = bufalloc(nlen+1);
586 memmove(str,str+st,nlen);
642 at = (at < 0 || at > len) ? len : at;
645 int lstr = (ls > 0) ? ls : strlen(s);
647 int lnew = len + lstr;
649 str = bufalloc(lnew+1);
653 memmove(str+at+lstr,str+at,(len-at));
655 memcpy(str+at,s,lstr);
661 if ((str = bufalloc(lstr+1))) {
687 return insert((
const char *)&sc[0], start);
698 return insert((
const char *)&si[0], start);
740 if (!str || len <= 0)
744 int l1 = s1 ? strlen(s1) : 0;
749 if (adjust(len,from,
to) <= 0)
753 int l2 = s2 ? strlen(s2) : 0;
758 int at =
find(s1,from);
759 while (at > -1 && at <= (
to-l1+1)) {
766 int nlen = (nr > 0) ? (len + nr*(l2-l1)) : len ;
770 str = bufalloc(nlen+1);
778 int at =
find(s1,from);
779 while (at > -1 && at <= (
to-l1+1)) {
780 int atn =
find(s1,at+l1);
781 atn = (atn == -1 || atn > (
to-l1+1)) ? len : atn;
782 int ln = atn - at - l1;
783 char *pc = str+at+nc*dd;
787 memmove(pc+l2,str+at+l1,ln);
792 }
else if (dd == 0) {
793 int at =
find(s1,from);
794 while (at > -1 && at <= (
to-l1+1)) {
795 memcpy(str+at,s2,l2);
802 while (at > -1 && at >= from) {
803 int ln = atn - at - l1;
804 char *pc = str + at + l1 + nc*dd;
806 memmove(pc,str+at+l1,ln);
811 if( at - l1 < 0 ) at = -1;
812 else at =
rfind(s1,at-l1);
837 if (st < 0 || st > (len-1))
847 nrem = (size > (len-st)) ? (len-st) : size;
853 int nlen = len - nrem;
856 memmove(str+st,str+st+nrem,len-st-nrem);
893 if (st < 0 || st > (len-1))
903 nlw = (size > (len-st)) ? (len-st) : size;
912 for (; i < st + nlw ; i++ ) {
913 if (str[i] > 0x40 && str[i] < 0x5b)
926 if (st < 0 || st > (len-1))
936 nup = (size > (len-st)) ? (len-st) : size;
945 for (; i < st + nup ; i++ ) {
946 if (str[i] > 0x60 && str[i] < 0x7b)
957 volatile char *buf = 0;
958 for (buf = (
volatile char *)str; len; buf[--len] = 0) {}
969 j = (j >= 0 && j < siz) ? j : 0;
970 k = (k >= j && k < siz) ? k : siz-1;
973 volatile char *buf = (
volatile char *)str;
978 while (str[len-1] == 0)
989 assign((
const char *)&s[0],0,-1);
998 const char s[] = {c,0};
1026 static char c =
'\0';
1029 if (i > -1 && i < len)
1125 if (s && (strlen(s) == (
unsigned int)len))
1126 if (!strncmp(str,s,len))
1137 if (!strncmp(str,s.
c_str(),len))
1162 return (*
this == ((
const char *)&s[0]));
1210 return XrdOucString::blksize;
1218 XrdOucString::blksize = bs;
1245 if (len <= 0 || from < 0 || from > (len-1))
1249 int pos =
find(del, from);
1252 if (pos == -1 || pos > from) {
1253 int last = (pos > 0) ? (pos - 1) : -1;
1254 tok.
assign(str, from, last);
1277 if (len <= 0)
return 0;
1280 if (from < 0 || from > (len-1)) from = 0;
1281 if (
to < from)
to = len - 1;
1283 char *c = str + from;
1288 while (c <= str +
to) {
1289 if (*c < 48 || *c > 57)
return 0;
1303 if (!
isdigit(from,
to))
return LONG_MAX;
1306 if (from < 0 || from > (len-1)) from = 0;
1307 if (
to < from)
to = len - 1;
1312 long out = strtol(&str[from], 0, 10);
XrdOucString operator+(const XrdOucString &s1, const char *s)
std::ostream & operator<<(std::ostream &os, const XrdOucString s)
void insert(const int i, int start=-1)
const char * c_str() const
void assign(const char *s, int j, int k=-1)
void upper(int pos, int size=0)
void setbuffer(char *buf)
int erase(int start=0, int size=0)
void reset(const char c, int j=0, int k=-1)
int matches(const char *s, char wch=' *')
int rfind(const char c, int start=STR_NPOS)
XrdOucString & operator+=(const int i)
int replace(const char *s1, const char *s2, int from=0, int to=-1)
int find(const char c, int start=0, bool forward=1)
static void setblksize(const int bs)
bool isdigit(int from=0, int to=-1)
long atoi(int from=0, int to=-1)
int form(const char *fmt,...)
int tokenize(XrdOucString &tok, int from, char del=':')
void lower(int pos, int size=0)
XrdOucString & operator=(const int i)
int operator==(const int i)
int keep(int start=0, int size=0)
static INT to(const char *buffer)