Esempio n. 1
0
void StringBuffer::append(int n) {
  char buf[12];
  int is_negative;
  int len;
  char *p = conv_10(n, &is_negative, buf + 12, &len);
  append(p, len);
}
Esempio n. 2
0
void StringBuffer::append(int64 n) {
  char buf[21];
  int is_negative;
  int len;
  char *p = conv_10(n, &is_negative, buf + 21, &len);
  append(p, len);
}
Esempio n. 3
0
/**
 * concat_is will incRef the output string
 */
StringData* concat_is(int64_t v1, StringData* v2) {
  char intbuf[21];
  // Convert the int to a string
  auto const s1 = conv_10(v1, intbuf + sizeof(intbuf));
  auto const s2 = v2->slice();
  return StringData::Make(s1, s2);
}
Esempio n. 4
0
static char *conv_apr_sockaddr(apr_sockaddr_t *sa, char *buf_end, int *len)
{
    char *p = buf_end;
    bool_int is_negative;
    int sub_len;
    char *ipaddr_str;

    p = conv_10(sa->port, TRUE, &is_negative, p, &sub_len);
    *--p = ':';
    apr_sockaddr_ip_get(&ipaddr_str, sa);
    sub_len = strlen(ipaddr_str);
#if APR_HAVE_IPV6
    if (sa->family == APR_INET6 &&
        !IN6_IS_ADDR_V4MAPPED(&sa->sa.sin6.sin6_addr)) {
        *(p - 1) = ']';
        p -= sub_len + 2;
        *p = '[';
        memcpy(p + 1, ipaddr_str, sub_len);
    }
    else
#endif
    {
        p -= sub_len;
        memcpy(p, ipaddr_str, sub_len);
    }

    *len = buf_end - p;
    return (p);
}
Esempio n. 5
0
StringData* buildStringData(int64_t n) {
  char tmpbuf[21];

  tmpbuf[20] = '\0';
  auto const sl = conv_10(n, &tmpbuf[20]);
  return StringData::Make(sl, CopyString);
}
Esempio n. 6
0
StringData* buildStringData(int n) {
  char tmpbuf[12];

  tmpbuf[11] = '\0';
  auto sl = conv_10(n, &tmpbuf[11]);
  return StringData::Make(sl, CopyString);
}
Esempio n. 7
0
/**
 * concat_is will incRef the output string
 */
StringData* concat_is(int64_t v1, StringData* v2) {
  char intbuf[21];
  // Convert the int to a string
  auto const s1 = conv_10(v1, intbuf + sizeof(intbuf));
  StringSlice s2 = v2->slice();
  StringData* ret = StringData::Make(s1, s2);
  ret->incRefCount();
  return ret;
}
Esempio n. 8
0
bool equalAsStr(int64 v1, litstr  v2) {
  char tmpbuf[21];
  char *p;
  int is_negative;
  int len;
  tmpbuf[20] = '\0';
  p = conv_10(v1, &is_negative, &tmpbuf[20], &len);
  return strcmp(p, v2) == 0;
}
Esempio n. 9
0
static char *conv_10_quad(widest_int num, register bool_int is_unsigned,
                     register bool_int *is_negative, char *buf_end,
                     register int *len)
{
    register char *p = buf_end;
    u_widest_int magnitude;

    /*
     * We see if we can use the faster non-quad version by checking the
     * number against the largest long value it can be. If <=, we
     * punt to the quicker version.
     */
    if ((num <= ULONG_MAX && is_unsigned) 
        || (num <= LONG_MAX && num >= LONG_MIN && !is_unsigned))
            return(conv_10( (wide_int)num, is_unsigned, is_negative,
               buf_end, len));

    if (is_unsigned) {
        magnitude = (u_widest_int) num;
        *is_negative = FALSE;
    }
    else {
        *is_negative = (num < 0);

        /*
         * On a 2's complement machine, negating the most negative integer 
         * results in a number that cannot be represented as a signed integer.
         * Here is what we do to obtain the number's magnitude:
         *      a. add 1 to the number
         *      b. negate it (becomes positive)
         *      c. convert it to unsigned
         *      d. add 1
         */
        if (*is_negative) {
            widest_int t = num + 1;

            magnitude = ((u_widest_int) -t) + 1;
        }
        else
            magnitude = (u_widest_int) num;
    }

    /*
     * We use a do-while loop so that we write at least 1 digit 
     */
    do {
        u_widest_int new_magnitude = magnitude / 10;

        *--p = (char) (magnitude - new_magnitude * 10 + '0');
        magnitude = new_magnitude;
    }
    while (magnitude);

    *len = buf_end - p;
    return (p);
}
Esempio n. 10
0
StringData* buildStringData(int64_t n) {
    char tmpbuf[21];
    char* p;
    int is_negative;
    int len;

    tmpbuf[20] = '\0';
    p = conv_10(n, &is_negative, &tmpbuf[20], &len);
    return StringData::Make(p, len, CopyString);
}
Esempio n. 11
0
StringData* buildStringData(int n) {
  char tmpbuf[12];
  char* p;
  int is_negative;
  int len;

  tmpbuf[11] = '\0';
  p = conv_10(n, &is_negative, &tmpbuf[11], &len);
  return NEW(StringData)(p, len, CopyString);
}
Esempio n. 12
0
static char *conv_os_thread_t(apr_os_thread_t *tid, char *buf_end, int *len)
{
    union {
        apr_os_thread_t tid;
        apr_uint64_t alignme;
    } u;
    int is_negative;

    u.tid = *tid;
    switch(sizeof(u.tid)) {
    case sizeof(apr_int32_t):
        return conv_10(*(apr_uint32_t *)&u.tid, TRUE, &is_negative, buf_end, len);
    case sizeof(apr_int64_t):
        return conv_10_quad(*(apr_uint64_t *)&u.tid, TRUE, &is_negative, buf_end, len);
    default:
        /* not implemented; stick 0 in the buffer */
        return conv_10(0, TRUE, &is_negative, buf_end, len);
    }
}
Esempio n. 13
0
bool equalAsStr(int64 v1, const StringData *v2) {
  char tmpbuf[21];
  char *p;
  int is_negative;
  int len;
  tmpbuf[20] = '\0';
  p = conv_10(v1, &is_negative, &tmpbuf[20], &len);
  if (len != v2->size()) {
    return false;
  }
  return memcmp(p, v2->data(), len) == 0;
}
Esempio n. 14
0
StringData* buildStringData(int n) {
  char tmpbuf[12];
  char* p;
  int is_negative;
  int len;

  TAINT_OBSERVER(TAINT_BIT_MUTATED, TAINT_BIT_NONE);

  tmpbuf[11] = '\0';
  p = conv_10(n, &is_negative, &tmpbuf[11], &len);
  return NEW(StringData)(p, len, CopyString);
}
Esempio n. 15
0
static char *conv_sockaddr_in(struct sockaddr_in *si, char *buf_end, int *len)
{
    char *p = buf_end;
    bool_int is_negative;
    int sub_len;

    p = conv_10(ntohs(si->sin_port), TRUE, &is_negative, p, &sub_len);
    *--p = ':';
    p = conv_in_addr(&si->sin_addr, p, &sub_len);

    *len = buf_end - p;
    return (p);
}
Esempio n. 16
0
String::String(int n) {
  char tmpbuf[12];
  char *p;
  int is_negative;
  int len;
  char *buf;

  tmpbuf[11] = '\0';
  p = conv_10(n, &is_negative, &tmpbuf[11], &len);

  buf = (char*)malloc(len + 1);
  memcpy(buf, p, len + 1); // including the null terminator.
  SmartPtr<StringData>::operator=(NEW(StringData)(buf, AttachString));
}
Esempio n. 17
0
void StringBuffer::append(int64 n) {
  char buf[21];
  int is_negative;
  int len;
  const StringData *sd = String::GetIntegerStringData(n);
  char *p;
  if (!sd) {
    p = conv_10(n, &is_negative, buf + 21, &len);
  } else {
    p = (char *)sd->data();
    len = sd->size();
  }
  append(p, len);
}
Esempio n. 18
0
String::String(int64 n) {
  char tmpbuf[21];
  char *p;
  int is_negative;
  int len;
  char *buf;

  tmpbuf[20] = '\0';
  p = conv_10(n, &is_negative, &tmpbuf[20], &len);

  buf = (char*)malloc(len + 1);
  memcpy(buf, p, len + 1); // including the null terminator.
  m_px = NEW(StringData)(buf, AttachString);
  m_px->incRefCount();
}
Esempio n. 19
0
void StringBuffer::append(int64_t n) {
  char buf[21];
  int len;
  const StringData *sd = String::GetIntegerStringData(n);
  char *p;
  if (!sd) {
    auto sl = conv_10(n, buf + 21);
    p = const_cast<char*>(sl.ptr);
    len = sl.len;
  } else {
    p = (char *)sd->data();
    len = sd->size();
  }
  append(p, len);
}
Esempio n. 20
0
void StringBuffer::append(int n) {
  char buf[12];
  int len;
  auto const sd = String::GetIntegerStringData(n);
  char *p;
  if (!sd) {
    auto sl = conv_10(n, buf + 12);
    p = const_cast<char*>(sl.data());
    len = sl.size();
  } else {
    p = (char *)sd->data();
    len = sd->size();
  }
  append(p, len);
}
Esempio n. 21
0
bool equalAsStr(int64_t v1, litstr  v2) {
  char tmpbuf[21];
  char *p;
  int is_negative;
  int len;
  const StringData *sd = String::GetIntegerStringData(v1);
  if (sd) {
    p = (char *)sd->data();
    len = sd->size();
  } else {
    tmpbuf[20] = '\0';
    p = conv_10(v1, &is_negative, &tmpbuf[20], &len);
  }
  return strcmp(p, v2) == 0;
}
Esempio n. 22
0
bool equalAsStr(int64_t v1, const StringData *v2) {
  char tmpbuf[21];
  char *p;
  int is_negative;
  int len;
  const StringData *sd = String::GetIntegerStringData(v1);
  if (sd) {
    p = (char *)sd->data();
    len = sd->size();
  } else {
    p = conv_10(v1, &is_negative, &tmpbuf[20], &len);
  }
  if (len != v2->size()) {
    return false;
  }
  return memcmp(p, v2->data(), len) == 0;
}
Esempio n. 23
0
String::String(int64 n) {
  char tmpbuf[21];
  char *p;
  int is_negative;
  int len;
  char *buf;

  TAINT_OBSERVER(TAINT_BIT_MUTATED, TAINT_BIT_NONE);

  tmpbuf[20] = '\0';
  p = conv_10(n, &is_negative, &tmpbuf[20], &len);

  buf = (char*)malloc(len + 1);
  memcpy(buf, p, len + 1); // including the null terminator.
  m_px = NEW(StringData)(buf, len, AttachString);
  m_px->setRefCount(1);
}
Esempio n. 24
0
static char *conv_in_addr(struct in_addr *ia, char *buf_end, apr_size_t *len)
{
    unsigned addr = ntohl(ia->s_addr);
    char *p = buf_end;
    int is_negative;
    apr_size_t sub_len;

    p = conv_10((addr & 0x000000FF)      , TRUE, &is_negative, p, &sub_len);
    *--p = '.';
    p = conv_10((addr & 0x0000FF00) >>  8, TRUE, &is_negative, p, &sub_len);
    *--p = '.';
    p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len);
    *--p = '.';
    p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len);

    *len = buf_end - p;
    return (p);
}
Esempio n. 25
0
/**
 * concat_si will incRef the output string
 * and decref its first argument
 */
StringData* concat_si(StringData* v1, int64_t v2) {
  char intbuf[21];
  auto const s2 = conv_10(v2, intbuf + sizeof(intbuf));
  if (v1->cowCheck()) {
    auto const s1 = v1->slice();
    auto const ret = StringData::Make(s1, s2);
    // Because v1 was shared, we know this won't release it.
    v1->decRefCount();
    return ret;
  }

  auto const ret = v1->append(s2);
  if (UNLIKELY(ret != v1)) {
    assert(v1->hasExactlyOneRef());
    v1->release();
  }
  return ret;
}
Esempio n. 26
0
/**
 * concat_si will incRef the output string
 * and decref its first argument
 */
StringData* concat_si(StringData* v1, int64_t v2) {
  char intbuf[21];
  auto const s2 = conv_10(v2, intbuf + sizeof(intbuf));
  if (v1->hasMultipleRefs()) {
    auto const s1 = v1->slice();
    auto const ret = StringData::Make(s1, s2);
    // Because v1->getCount() is greater than 1, we know we will never
    // have to release the string here
    v1->decRefCount();
    return ret;
  }

  auto const ret = v1->append(s2);
  if (UNLIKELY(ret != v1)) {
    assert(v1->hasExactlyOneRef());
    v1->release();
  }
  return ret;
}
Esempio n. 27
0
static char *conv_os_thread_t_hex(apr_os_thread_t *tid, char *buf_end, apr_size_t *len)
{
    union {
        apr_os_thread_t tid;
        apr_uint64_t u64;
        apr_uint32_t u32;
    } u;
    int is_negative;

    u.tid = *tid;
    switch(sizeof(u.tid)) {
    case sizeof(apr_int32_t):
        return conv_p2(u.u32, 4, 'x', buf_end, len);
    case sizeof(apr_int64_t):
        return conv_p2_quad(u.u64, 4, 'x', buf_end, len);
    default:
        /* not implemented; stick 0 in the buffer */
        return conv_10(0, TRUE, &is_negative, buf_end, len);
    }
}
Esempio n. 28
0
/* Must be passed a buffer of size NUM_BUF_SIZE where buf_end points
 * to 1 byte past the end of the buffer. */
static char *conv_apr_sockaddr(apr_sockaddr_t *sa, char *buf_end, apr_size_t *len)
{
    char *p = buf_end;
    int is_negative;
    apr_size_t sub_len;
    char *ipaddr_str;

    p = conv_10(sa->port, TRUE, &is_negative, p, &sub_len);
    *--p = ':';
    ipaddr_str = buf_end - NUM_BUF_SIZE;
    if (apr_sockaddr_ip_getbuf(ipaddr_str, sa->addr_str_len, sa)) {
        /* Should only fail if the buffer is too small, which it
         * should not be; but fail safe anyway: */
        *--p = '?';
        *len = buf_end - p;
        return p;
    }
    sub_len = strlen(ipaddr_str);
#if APR_HAVE_IPV6
    if (sa->family == APR_INET6 &&
        !IN6_IS_ADDR_V4MAPPED(&sa->sa.sin6.sin6_addr)) {
        *(p - 1) = ']';
        p -= sub_len + 2;
        *p = '[';
        memcpy(p + 1, ipaddr_str, sub_len);
    }
    else
#endif
    {
        p -= sub_len;
        memcpy(p, ipaddr_str, sub_len);
    }

    *len = buf_end - p;
    return (p);
}
Esempio n. 29
0
void printPair(int fd,
               folly::StringPiece first,
               int64_t second) {
  char buf[24];
  printPair(fd, first, conv_10(second, buf + sizeof buf));
}
Esempio n. 30
0
static const StringData* convert_integer_helper(int64_t n) {
  char tmpbuf[21];
  tmpbuf[20] = '\0';
  auto sl = conv_10(n, &tmpbuf[20]);
  return makeStaticString(sl);
}