/*
 * Copyright (c) 2006 Mode2 inc.
 * Copyright (c) 2007 - 2008 BROADTECH INC.
 * Copyright (c) 2006 - 2008 Kazuaki ODA
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the company nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * $Id: ctr_util.h 540 2008-08-30 18:44:20Z oda $
 */

#ifndef __CTR_UTIL_H__
#define __CTR_UTIL_H__

#include "httpd.h"
#include "apr_hash.h"
#include "apr_pools.h"

#define CTR_HASH_SET(_h, _key, _v)                                      \
    apr_hash_set((_h), (_key), strlen(_key), (_v))
#define CTR_HASH_GET(_h, _key)                                          \
    apr_hash_get((_h), (_key), strlen(_key))

#define CTR_ARRAY_LAST(_a)                                              \
    (apr_is_empty_array(_a) ?                                           \
     NULL : (_a)->elts + (_a)->elt_size * ((_a)->nelts - 1))

char *ctr_trim(char *s);
char *ctr_trim_head(char *s);
char *ctr_trim_last(char *s);
char *ctr_trim_newlines(char *s);
char *ctr_trim_head_newlines(char *s);
char *ctr_trim_last_newlines(char *s);
char *ctr_trim_head_newline(char *s);
char *ctr_trim_last_newline(char *s);
char *ctr_del_spaces(char *s);
char *ctr_unite_spaces(char *s);
char *ctr_tolower_str(char *s);
int ctr_isspace_str(const char *s);
int ctr_isdigit_str(const char *s);
int ctr_isdigit_strn(const char *s, apr_size_t len);
int ctr_isxdigit_str(const char *s);
int ctr_isxdigit_strn(const char *s, apr_size_t len);
int ctr_is2byteschar(const char *s);
int ctr_startwith(const char *msg, const char *word);
int ctr_casestartwith(const char *msg, const char *word);
int ctr_endwith(const char *msg, const char *word);
int ctr_caseendwith(const char *msg, const char *word);
void ctr_char_split(const char *src, const char **dst1,
                    const char **dst2, char sep, apr_pool_t *pool);
char *ctr_uniqstr_get(apr_pool_t *pool);
char *ctr_uri_suffix_remove(const char *uri, const char **suffix,
                            apr_pool_t *pool);
apr_table_t *ctr_args_get(const request_rec *r);
char *ctr_uri_escape(const char *s, apr_pool_t *pool);
char *ctr_html_escape(const char *s, apr_pool_t *pool);
char *ctr_html_unescape(char *s, apr_pool_t *pool);
char *ctr_html_text_unescape(char *s, apr_pool_t *pool);

#endif  /* __CTR_UTIL_H__ */
