/*1* Copyright (c) 2010 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2010 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include "baselocl.h"36#include <string.h>3738static void39string_dealloc(void *ptr)40{41}4243static int44string_cmp(void *a, void *b)45{46return strcmp(a, b);47}4849static unsigned long50string_hash(void *ptr)51{52const char *s = ptr;53unsigned long n;5455for (n = 0; *s; ++s)56n += *s;57return n;58}5960struct heim_type_data _heim_string_object = {61HEIM_TID_STRING,62"string-object",63NULL,64string_dealloc,65NULL,66string_cmp,67string_hash68};6970/**71* Create a string object72*73* @param string the string to create, must be an utf8 string74*75* @return string object76*/7778heim_string_t79heim_string_create(const char *string)80{81size_t len = strlen(string);82heim_string_t s;8384s = _heim_alloc_object(&_heim_string_object, len + 1);85if (s)86memcpy(s, string, len + 1);87return s;88}8990/**91* Return the type ID of string objects92*93* @return type id of string objects94*/9596heim_tid_t97heim_string_get_type_id(void)98{99return HEIM_TID_STRING;100}101102/**103* Get the string value of the content.104*105* @param string the string object to get the value from106*107* @return a utf8 string108*/109110const char *111heim_string_get_utf8(heim_string_t string)112{113return (const char *)string;114}115116117