Exemple #1
0
static void
str_split_text_common(struct mystr* p_src, struct mystr* p_rhs,
                      const char* p_text, int is_reverse)
{
  struct str_locate_result locate_result;
  unsigned int indexx;
  unsigned int search_len = vsf_sysutil_strlen(p_text);
  if (is_reverse)
  {
    locate_result = str_locate_text_reverse(p_src, p_text);
  }
  else
  {
    locate_result = str_locate_text(p_src, p_text);
  }
  /* Not found? */
  if (!locate_result.found)
  {
    str_empty(p_rhs);
    return;
  }
  indexx = locate_result.index;
  if (indexx + search_len > p_src->len)
  {
    bug("indexx invalid in str_split_text");
  } 
  /* Build rhs */
  private_str_alloc_memchunk(p_rhs, p_src->p_buf + indexx + search_len,
                             p_src->len - indexx - search_len);
  /* Build lhs */
  str_trunc(p_src, indexx);
}
Exemple #2
0
int
str_getline(const struct mystr* p_str, struct mystr* p_line_str,
            unsigned int* p_pos)
{
  unsigned int start_pos = *p_pos;
  unsigned int curr_pos = start_pos;
  unsigned int buf_len = str_getlen(p_str);
  const char* p_buf = str_getbuf(p_str);
  unsigned int out_len;
  if (start_pos > buf_len)
  {
    bug("p_pos out of range in str_getline");
  }
  str_empty(p_line_str);
  if (start_pos == buf_len)
  {
    return 0;
  }
  while (curr_pos < buf_len && p_buf[curr_pos] != '\n')
  {
    curr_pos++;
  }
  out_len = curr_pos - start_pos;
  /* If we ended on a \n - skip it */
  if (curr_pos < buf_len && p_buf[curr_pos] == '\n')
  {
    curr_pos++;
  }
  private_str_alloc_memchunk(p_line_str, p_buf + start_pos, out_len);
  *p_pos = curr_pos;
  return 1;
}
Exemple #3
0
void
str_left(const struct mystr* p_str, struct mystr* p_out, unsigned int chars)
{
  if (chars > p_str->len)
  {
    bug("chars invalid in str_left");
  }
  private_str_alloc_memchunk(p_out, p_str->p_buf, chars);
}
Exemple #4
0
void
str_right(const struct mystr* p_str, struct mystr* p_out, unsigned int chars)
{
  unsigned int indexx = p_str->len - chars;
  if (chars > p_str->len)
  {
    bug("chars invalid in str_right");
  }
  private_str_alloc_memchunk(p_out, p_str->p_buf + indexx, chars);
}
Exemple #5
0
void
str_mid_to_end(const struct mystr* p_str, struct mystr* p_out,
               unsigned int indexx)
{
  if (indexx > p_str->len)
  {
    bug("invalid indexx in str_mid_to_end");
  }
  private_str_alloc_memchunk(p_out, p_str->p_buf + indexx,
                             p_str->len - indexx);
}
Exemple #6
0
void
str_alloc_alt_term(struct mystr* p_str, const char* p_src, char term)
{
  const char* p_search = p_src;
  unsigned int len = 0;
  while (*p_search != term)
  {
    p_search++;
    len++;
  }
  private_str_alloc_memchunk(p_str, p_src, len);
}
Exemple #7
0
const char*
str_getbuf(const struct mystr* p_str)
{
  if (p_str->p_buf == 0)
  {
    if (p_str->len != 0 || p_str->alloc_bytes != 0)
    {
      bug("p_buf NULL and len or alloc_bytes != 0 in str_getbuf");
    }
    private_str_alloc_memchunk((struct mystr*)p_str, 0, 0);
  }
  return p_str->p_buf;
}
Exemple #8
0
void
str_alloc_alt_term(struct mystr* p_str, const char* p_src, char term)
{
  const char* p_search = p_src;
  unsigned int len = 0;
  while (*p_search != term)
  {
    p_search++;
    len++;
    if (len == 0)
    {
      bug("integer overflow");
    }
  }
  private_str_alloc_memchunk(p_str, p_src, len);
}
Exemple #9
0
/* Public functions */
void
str_alloc_text(struct mystr* p_str, const char* p_src)
{
  unsigned int len = vsf_sysutil_strlen(p_src);
  private_str_alloc_memchunk(p_str, p_src, len);
}
Exemple #10
-4
void
str_copy(struct mystr* p_dest, const struct mystr* p_src)
{
  private_str_alloc_memchunk(p_dest, p_src->p_buf, p_src->len);
}