double CStringEx::GetDouble() { TestExp(); double f; f = atodn(GetBuffer(GetLength()),GetLength()); return f; }
static int chkdbl(struct facets *fp,char *s,int n) { int ok=1,nan=s_tokcmpn("NaN",s,n)==0; double d=atodn(s,n); if(fp->set&(1<<FCT_MIN_EXCLUSIVE)) ok=ok&&!nan&&d>atod(fp->minExclusive); if(fp->set&(1<<FCT_MIN_INCLUSIVE)) ok=ok&&!nan&&d>=atod(fp->minInclusive); if(fp->set&(1<<FCT_MAX_INCLUSIVE)) ok=ok&&!nan&&d<=atod(fp->maxInclusive); if(fp->set&(1<<FCT_MAX_EXCLUSIVE)) ok=ok&&!nan&&d<atod(fp->maxExclusive); return ok; }
/* Convert textual form of id into a (temporary) struct id. * Note that if the id is to be kept, unshare_id_content will be necessary. */ err_t atoid(char *src, struct id *id, bool myid_ok) { err_t ugh = NULL; *id = empty_id; if (myid_ok && streq("%myid", src)) { id->kind = ID_MYID; } else if (streq("%fromcert", src)) { id->kind = ID_FROMCERT; } else if (streq("%none", src)) { id->kind = ID_NONE; } else if (strchr(src, '=') != NULL) { /* we interpret this as an ASCII X.501 ID_DER_ASN1_DN */ id->kind = ID_DER_ASN1_DN; id->name.ptr = temporary_cyclic_buffer(); /* assign temporary buffer */ id->name.len = 0; /* convert from LDAP style or openssl x509 -subject style to ASN.1 DN * discard optional @ character in front of DN */ ugh = atodn((*src == '@')?src+1:src, &id->name); } else if (strchr(src, '@') == NULL) { if (streq(src, "%any") || streq(src, "0.0.0.0")) { /* any ID will be accepted */ id->kind = ID_NONE; } else { /* !!! this test is not sufficient for distinguishing address families. * We need a notation to specify that a FQDN is to be resolved to IPv6. */ const struct af_info *afi = strchr(src, ':') == NULL ? &af_inet4_info: &af_inet6_info; id->kind = afi->id_addr; ugh = ttoaddr(src, 0, afi->af, &id->ip_addr); } } else { if (*src == '@') { if (*(src+1) == '#') { /* if there is a second specifier (#) on the line * we interprete this as ID_KEY_ID */ id->kind = ID_KEY_ID; id->name.ptr = (unsigned char *)src; /* discard @~, convert from hex to bin */ ugh = ttodata(src+2, 0, 16, (char *)id->name.ptr , strlen(src), &id->name.len); } else if (*(src+1) == '~') { /* if there is a second specifier (~) on the line * we interprete this as a binary ID_DER_ASN1_DN */ id->kind = ID_DER_ASN1_DN; id->name.ptr = (unsigned char *)src; /* discard @~, convert from hex to bin */ ugh = ttodata(src+2, 0, 16, (char *)id->name.ptr , strlen(src), &id->name.len); } else if (*(src+1) == '[') { /* if there is a second specifier ([) on the line * we interprete this as a text ID_KEY_ID, and we remove * a trailing ", if there is one. */ int len = strlen(src+2); id->kind = ID_KEY_ID; id->name.ptr = (unsigned char *)src+2; if(src[len+2]==']') { src[len+2-1]='\0'; len--; } id->name.len = len; } else { id->kind = ID_FQDN; id->name.ptr = (unsigned char *)src+1; /* discard @ */ id->name.len = strlen(src)-1; } } else { /* We leave in @, as per DOI 4.6.2.4 * (but DNS wants . instead). */ id->kind = ID_USER_FQDN; id->name.ptr = (unsigned char *)src; id->name.len = strlen(src); } } return ugh; }
static int dblcmpn(char *val,char *s,char n) { double d1,d2; return s_tokcmpn(val,s,n)==0?0 : s_tokcmpn(val,"NaN",3)==0||s_tokcmpn("NaN",s,n)==0?1 : (d1=atod(val),d2=atodn(s,n),d1<d2?-1:d1>d2?1:0); }
static double atod(char *s) {return atodn(s,strlen(s));}