⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 str.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 4 页
字号:
		}		if (!c)			break;		map[n++] = c;	}	m = 0;	tran = GDKmalloc(strlen(transtr) * sizeof(int));	s = (unsigned char *) transtr;	for (;;) {		#line 1217 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"	if (*s < 0x80) {		(c) = *(s)++;	} else if (*(s) < 0xE0) {		(c)  = (*(s)++ & 0x1F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*(s) < 0xF0) {		(c)  = (*(s)++ & 0x0F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*s < 0xF8) {		(c)  = (*(s)++ & 0x07) << 18;		(c) |= (*(s)++ & 0x3F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*s < 0xFC) {		(c)  = (*(s)++ & 0x03) << 24;		(c) |= (*(s)++ & 0x3F) << 18;		(c) |= (*(s)++ & 0x3F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*s < 0xFE) {		(c)  = (*(s)++ & 0x01) << 30;		(c) |= (*(s)++ & 0x3F) << 24;		(c) |= (*(s)++ & 0x3F) << 18;		(c) |= (*(s)++ & 0x3F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else {		(c) = int_nil;	}#line 1867 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"		if (c == int_nil) {			GDKfree(map);			GDKfree(tran);			* (ptr *) res = (ptr) ATOMnil(TYPE_str);			return GDK_SUCCEED;		}		if (!c)			break;		tran[m++] = c;	}	/* now do the translations */	dst = (unsigned char *) GDKmalloc(strlen(src) * 6 + 1); /* more than enough */	*res = (char *) dst;	s = (unsigned char *) src;	for (;;) {		#line 1217 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"	if (*s < 0x80) {		(c) = *(s)++;	} else if (*(s) < 0xE0) {		(c)  = (*(s)++ & 0x1F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*(s) < 0xF0) {		(c)  = (*(s)++ & 0x0F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*s < 0xF8) {		(c)  = (*(s)++ & 0x07) << 18;		(c) |= (*(s)++ & 0x3F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*s < 0xFC) {		(c)  = (*(s)++ & 0x03) << 24;		(c) |= (*(s)++ & 0x3F) << 18;		(c) |= (*(s)++ & 0x3F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else if (*s < 0xFE) {		(c)  = (*(s)++ & 0x01) << 30;		(c) |= (*(s)++ & 0x3F) << 24;		(c) |= (*(s)++ & 0x3F) << 18;		(c) |= (*(s)++ & 0x3F) << 12;		(c) |= (*(s)++ & 0x3F) << 6;		(c) |= (*(s)++ & 0x3F);	} else {		(c) = int_nil;	}#line 1883 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"		if (c == int_nil) {			GDKfree(map);			GDKfree(tran);			GDKfree(*res);			* (ptr *) res = (ptr) ATOMnil(TYPE_str);			return GDK_SUCCEED;		}		if (!c)			break;		for (i = 0; i < n; i++)			if (map[i] == c) {				if (i < m) {					#line 1248 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"	if ((tran[i]) < 0#if SIZEOF_INT > 4	    || (int) (tran[i]) >= 0x80000000#endif	   ) {		*(dst)++ = chr_nil;	} else if ((tran[i]) < 0x80) {		*(dst)++ = (tran[i]);	} else if ((tran[i]) < 0x800) {		*(dst)++ = 0xC0 | ((tran[i]) >> 6);		*(dst)++ = 0x80 | ((tran[i]) & 0x3F);	} else if ((tran[i]) < 0x10000) {		*(dst)++ = 0xE0 | ((tran[i]) >> 12);		*(dst)++ = 0x80 | (((tran[i]) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((tran[i]) & 0x3F);	} else if ((tran[i]) < 0x200000) {		*(dst)++ = 0xF0 | ((tran[i]) >> 18);		*(dst)++ = 0x80 | (((tran[i]) >> 12) & 0x3F);		*(dst)++ = 0x80 | (((tran[i]) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((tran[i]) & 0x3F);	} else if ((tran[i]) < 0x4000000) {		*(dst)++ = 0xF8 | ((tran[i]) >> 24);		*(dst)++ = 0x80 | (((tran[i]) >> 18) & 0x3F);		*(dst)++ = 0x80 | (((tran[i]) >> 12) & 0x3F);		*(dst)++ = 0x80 | (((tran[i]) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((tran[i]) & 0x3F);	} else /* if ((tran[i]) < 0x80000000) */ {		*(dst)++ = 0xFC | ((tran[i]) >> 30);		*(dst)++ = 0x80 | (((tran[i]) >> 24) & 0x3F);		*(dst)++ = 0x80 | (((tran[i]) >> 18) & 0x3F);		*(dst)++ = 0x80 | (((tran[i]) >> 12) & 0x3F);		*(dst)++ = 0x80 | (((tran[i]) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((tran[i]) & 0x3F);	}#line 1896 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"				}				break;			}		if (i == n) {			/* not found */			#line 1248 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"	if ((c) < 0#if SIZEOF_INT > 4	    || (int) (c) >= 0x80000000#endif	   ) {		*(dst)++ = chr_nil;	} else if ((c) < 0x80) {		*(dst)++ = (c);	} else if ((c) < 0x800) {		*(dst)++ = 0xC0 | ((c) >> 6);		*(dst)++ = 0x80 | ((c) & 0x3F);	} else if ((c) < 0x10000) {		*(dst)++ = 0xE0 | ((c) >> 12);		*(dst)++ = 0x80 | (((c) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((c) & 0x3F);	} else if ((c) < 0x200000) {		*(dst)++ = 0xF0 | ((c) >> 18);		*(dst)++ = 0x80 | (((c) >> 12) & 0x3F);		*(dst)++ = 0x80 | (((c) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((c) & 0x3F);	} else if ((c) < 0x4000000) {		*(dst)++ = 0xF8 | ((c) >> 24);		*(dst)++ = 0x80 | (((c) >> 18) & 0x3F);		*(dst)++ = 0x80 | (((c) >> 12) & 0x3F);		*(dst)++ = 0x80 | (((c) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((c) & 0x3F);	} else /* if ((c) < 0x80000000) */ {		*(dst)++ = 0xFC | ((c) >> 30);		*(dst)++ = 0x80 | (((c) >> 24) & 0x3F);		*(dst)++ = 0x80 | (((c) >> 18) & 0x3F);		*(dst)++ = 0x80 | (((c) >> 12) & 0x3F);		*(dst)++ = 0x80 | (((c) >> 6) & 0x3F);		*(dst)++ = 0x80 | ((c) & 0x3F);	}#line 1902 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"		}	}	*dst = 0;	GDKfree(map);	GDKfree(tran);	*res = GDKrealloc(*res, strlen(*res) + 1);	return GDK_SUCCEED;}intstrSplit(BAT **Res, str s, str sep){	size_t seplen = strlen(sep);	char *d, *x;	BAT *res;	oid n = oid_nil;	if (seplen == 0) {		return GDK_FAIL;	}	x = d = GDKstrdup(s);	if (d == NULL)		return GDK_FAIL;	res = BATnew(TYPE_void, TYPE_str, BUFSIZ);	if (res == NULL) {		GDKfree(x);		return GDK_FAIL;	}	for (;;) {		char *e = strstr(d, sep);			if (!e)			break;			*e = 0;		BUNins(res, (ptr) &n, d, FALSE);		d = e + seplen;	}	/* remove the test if sep is to be a real separator, now we	   don't return an empty final string if the source ends with	   a separator (this is to accommodate Niels) */	if (*d)		BUNins(res, (ptr) &n, d, FALSE);	GDKfree(x);	*Res = res;	return GDK_SUCCEED;}intchrSplit(BAT **Res, str s){	char * d = s;	oid n = oid_nil;	BAT *res = BATnew(TYPE_void, TYPE_chr, strlen(s));	BATseqbase(res,(oid) 0);	if (res == NULL)		return GDK_FAIL;	while (*d) 		BUNins(res, (ptr) &n, (ptr) d++, FALSE);	*Res = res;	return GDK_SUCCEED;}#line 1974 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"#include "mal_exception.h"strSTRfindUnescapedOccurrence(str b, str c, str esc){	str t;	t= strstr(b,c);	while( t){		/* check for escaped version */		if( t>b && *esc == *(t-1) ) {			t= strstr(t+1,c);		} else return t;	}	return 0;}#line 1992 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"intSTRlike(str s, str pat, str esc){	str t,p;	t= s;	for( p= pat; *p && *t; p++){		if(esc && *p == *esc) {			p++;			if( *p != *t) return FALSE;			t++;		} else		if( *p == '_') t++;		else		if( *p == '%'){			p++;			while(*p == '%') p++;			if( *p == 0) return TRUE; /* tail is acceptable */			for(; *p && *t; t++)				if( STRlike(t,p,esc))					return TRUE;			if( *p == 0 && *t == 0) return TRUE;			return FALSE;		} else		if( *p == *t) t++;		else return FALSE;	}	if( *p == '%' && *(p+1)==0) return TRUE;	return *t == 0 && *p == 0;}strSTRfindOccurrence(str *ret, str *s, str *pat, str *esc){	*ret = STRfindUnescapedOccurrence(*s,*pat,*esc);	if( *ret) *ret= GDKstrdup(*ret);	return MAL_SUCCEED;}strSTRlikewrap(bit *ret, str *s, str *pat, str *esc){	*ret = STRlike(*s,*pat,*esc);	return MAL_SUCCEED;}strSTRlikewrap2(bit *ret, str *s, str *pat){	*ret = STRlike(*s,*pat,0);	return MAL_SUCCEED;}strSTRtostr(str *res, str *src){	if( *src == 0)		*res= GDKstrdup(str_nil);	else *res = GDKstrdup(*src);	return MAL_SUCCEED;}#line 2052 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"strSTRConcat(str *res, str *val1, str *val2){	strConcat(res, *val1, *val2, TYPE_str);	return MAL_SUCCEED;}strSTRLength(int *res, str *arg1){	strLength(res, *arg1);	return MAL_SUCCEED;}strSTRBytes(int *res, str *arg1){	strBytes(res, *arg1);	return MAL_SUCCEED;}strSTRTail(str *res, str *arg1, int *offset){	strTail(res, *arg1, offset);	return MAL_SUCCEED;}strSTRSubString(str *res, str *arg1, int *offset, int *length){	strSubString(res, *arg1, offset, length);	return MAL_SUCCEED;}strSTRFromWChr(str *res, int *at){	strFromWChr(res, at);	return MAL_SUCCEED;}strSTRWChrAt(int *res, str *arg1, int *at){	strWChrAt(res, *arg1, at);	return MAL_SUCCEED;}strSTRcodeset(str *res){	codeset(res);	return MAL_SUCCEED;}strSTRIconv(str *res, str *o, str *fp, str *tp){	strIconv(res, *o, *fp, *tp);	return MAL_SUCCEED;}strSTRChrAt(chr *res, str *arg1, int *at){	strChrAt(res, *arg1, at);	return MAL_SUCCEED;}strSTRPrefix(bit *res, str *arg1, str *arg2){	strPrefix(res, *arg1, *arg2);	return MAL_SUCCEED;}strSTRSuffix(bit *res, str *arg1, str *arg2){	strSuffix(res, *arg1, *arg2);	return MAL_SUCCEED;}strSTRLower(str *res, str *arg1){	strLower(res, *arg1);	return MAL_SUCCEED;}strSTRUpper(str *res, str *arg1){	strUpper(res, *arg1);	return MAL_SUCCEED;}strSTRChrSearch(int *res, str *arg1, chr *c){	strChrSearch(res, *arg1, c);	return MAL_SUCCEED;}strSTRstrSearch(int *res, str *arg1, str *arg2){	strStrSearch(res, *arg1, *arg2);	return MAL_SUCCEED;}strSTRReverseStrSearch(int *res, str *arg1, str *arg2){	strReverseStrSearch(res, *arg1, *arg2);	return MAL_SUCCEED;}strSTRchrSearch(int *res, str *arg1, chr *c){	strReverseChrSearch(res, *arg1, c);	return MAL_SUCCEED;}strSTRReverseChrSearch(int *res, str *arg1, chr *c){	strReverseChrSearch(res, *arg1, c);	return MAL_SUCCEED;}strSTRStrip(str *res, str *arg1){	strStrip(res, *arg1);	return MAL_SUCCEED;}strSTRLtrim(str *res, str *arg1){	strLtrim(res, *arg1);	return MAL_SUCCEED;}strSTRRtrim(str *res, str *arg1){	strRtrim(res, *arg1);	return MAL_SUCCEED;}strSTRSubstitute(str *res, str *arg1, str *arg2, str *arg3, bit *g){	strSubstitute(res, *arg1, *arg2, *arg3, g);	return MAL_SUCCEED;}#line 2216 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"str STRascii(int *ret, str *s){	int offset=0;	return STRWChrAt(ret,s,&offset);}strSTRsubstringTail(str *ret, str *s, int *start){	int offset= *start;	if( offset <1) offset =1;	offset--;	return STRTail(ret, s, &offset);}strSTRsubstring(str *ret, str *s, int *start, int *l){	int offset= *start;	if( offset <1) offset =1;	offset--;	return STRSubString(ret, s, &offset, l);}strSTRprefix(str *ret, str *s, int *l){	int start =0;	return STRSubString(ret,s,&start,l);}strSTRsuffix(str *ret, str *s, int *l){	int start = strlen(*s)- *l;	return STRSubString(ret,s,&start,l);}strSTRlocate(int *ret, str *s1, str *s2){	int p;	strStrSearch(&p, *s2, *s1);	*ret=  p>=0? p+1:0;	return MAL_SUCCEED;}strSTRlocate2(int *ret, str *s1, str *s2, int *start){	int p;	str dummy;	strTail(&dummy, *s1, start);	strStrSearch(&p, *s2, dummy);	if( dummy) GDKfree(dummy);	*ret=  p>=0? p+1:0;	return MAL_SUCCEED;}strSTRinsert(str *ret, str *s, int *start, int *l, str *s2){	str v;	if(strcmp(*s2,str_nil) ==0 || strcmp(*s,str_nil)==0 )		*ret = GDKstrdup( (str)str_nil);	else {		if( *start <0) *start =1;		v= *ret = GDKmalloc(strlen(*s)+strlen(*s2)+1 );		strncpy(v, *s,*start);		v[*start]=0;		strcat(v,*s2);		if( *start + *l < (int) strlen(*s)) 			strcat(v,*s + *start + *l);	}	return MAL_SUCCEED;}strSTRreplace(str *ret, str *s1, str *s2, str *s3){	bit flag= TRUE;	return STRSubstitute(ret,s1,s2,s3,&flag);}strSTRrepeat(str *ret, str *s, int *c){	str t;	int i;	size_t l;	if( *c < 0 || strcmp(*s,str_nil)==0 )		*ret= GDKstrdup(str_nil);	else {		l= strlen(*s);		t= *ret = GDKmalloc( *c * l +1);		*t = 0;				for(i= *c; i>0; i--,t+= l) 			strcat(t, *s);	}	return MAL_SUCCEED;}strSTRspace(str *ret, int *l){	char buf[]= " ", *s= buf;	return STRrepeat(ret,&s,l);}strSTRstringLength(int *res, str *s){	str r = NULL;	strRtrim(&r, *s);	strLength(res, r);	GDKfree(r);	return MAL_SUCCEED;}#line 2326 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/atoms/str.mx"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -