1 /*
2 *
3 * C++ Portable Types Library (PTypes)
4 * Version 2.1.1 Released 27-Jun-2007
5 *
6 * Copyright (C) 2001-2007 Hovik Melikyan
7 *
8 * http://www.melikyan.com/ptypes/
9 *
10 */
11
12 #include "ptypes.h"
13
14
15 PTYPES_BEGIN
16
17
18 typedef _textitem* ptextitem;
19
20
textmap(bool casesens)21 textmap::textmap(bool casesens)
22 : tobjlist<_textitem>(true)
23 {
24 config.sorted = true;
25 config.casesens = casesens;
26 }
27
28
~textmap()29 textmap::~textmap()
30 {
31 }
32
33
compare(const void * key,const void * item) const34 int textmap::compare(const void* key, const void* item) const
35 {
36 if (config.casesens)
37 return strcmp(pconst(key), ptextitem(item)->key);
38 else
39 return strcasecmp(pconst(key), ptextitem(item)->key);
40 }
41
42
get(const char * key) const43 const string& textmap::get(const char* key) const
44 {
45 int index;
46 if (search(key, index))
47 return dogetvalue(index);
48 else
49 return nullstring;
50 }
51
52
put(const string & key,const string & value)53 int textmap::put(const string& key, const string& value)
54 {
55 int index;
56 if (search(pconst(key), index))
57 {
58 if (isempty(value))
59 dodel(index);
60 else
61 doget(index)->value = value;
62 }
63 else if (!isempty(value))
64 doins(index, new _textitem(key, value));
65 return index;
66 }
67
68
indexof(const char * key) const69 int textmap::indexof(const char* key) const
70 {
71 int index;
72 if (search(key, index))
73 return index;
74 else
75 return -1;
76 }
77
78
79 PTYPES_END
80