2009-07-08 13:19:16 -07:00
|
|
|
/*
|
2009-07-15 10:57:17 -07:00
|
|
|
* Copyright (c) 2008, 2009 Nicira Networks.
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
2009-07-08 13:19:16 -07:00
|
|
|
*
|
2009-06-15 15:11:30 -07:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-07-08 13:19:16 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DYNAMIC_STRING_H
|
|
|
|
#define DYNAMIC_STRING_H 1
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "compiler.h"
|
|
|
|
|
|
|
|
struct tm;
|
|
|
|
|
|
|
|
struct ds {
|
|
|
|
char *string; /* Null-terminated string. */
|
|
|
|
size_t length; /* Bytes used, not including null terminator. */
|
|
|
|
size_t allocated; /* Bytes allocated, not including null terminator. */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DS_EMPTY_INITIALIZER { NULL, 0, 0 }
|
|
|
|
|
|
|
|
void ds_init(struct ds *);
|
|
|
|
void ds_clear(struct ds *);
|
|
|
|
void ds_truncate(struct ds *, size_t new_length);
|
|
|
|
void ds_reserve(struct ds *, size_t min_length);
|
|
|
|
char *ds_put_uninit(struct ds *, size_t n);
|
|
|
|
void ds_put_char(struct ds *, char);
|
2009-11-04 14:55:53 -08:00
|
|
|
void ds_put_utf8(struct ds *, int uc);
|
2009-07-08 13:19:16 -07:00
|
|
|
void ds_put_char_multiple(struct ds *, char, size_t n);
|
|
|
|
void ds_put_buffer(struct ds *, const char *, size_t n);
|
|
|
|
void ds_put_cstr(struct ds *, const char *);
|
2009-11-16 16:55:35 -08:00
|
|
|
void ds_put_and_free_cstr(struct ds *, char *);
|
2009-07-08 13:19:16 -07:00
|
|
|
void ds_put_format(struct ds *, const char *, ...) PRINTF_FORMAT(2, 3);
|
|
|
|
void ds_put_format_valist(struct ds *, const char *, va_list)
|
|
|
|
PRINTF_FORMAT(2, 0);
|
|
|
|
void ds_put_printable(struct ds *, const char *, size_t);
|
|
|
|
void ds_put_strftime(struct ds *, const char *, const struct tm *)
|
|
|
|
STRFTIME_FORMAT(2);
|
|
|
|
void ds_put_hex_dump(struct ds *ds, const void *buf_, size_t size,
|
|
|
|
uintptr_t ofs, bool ascii);
|
|
|
|
int ds_get_line(struct ds *, FILE *);
|
|
|
|
|
|
|
|
char *ds_cstr(struct ds *);
|
2009-07-15 10:57:17 -07:00
|
|
|
char *ds_steal_cstr(struct ds *);
|
2009-07-08 13:19:16 -07:00
|
|
|
void ds_destroy(struct ds *);
|
|
|
|
|
|
|
|
int ds_last(const struct ds *);
|
|
|
|
void ds_chomp(struct ds *, int c);
|
|
|
|
|
|
|
|
#endif /* dynamic-string.h */
|