mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
DtMmdb: replace ostring with std::string.
This commit is contained in:
parent
ba49a9e161
commit
c79224b367
26 changed files with 71 additions and 514 deletions
|
@ -48,9 +48,10 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "utility/debug.h"
|
||||
#include "compression/code.h"
|
||||
|
||||
encoding_unit::encoding_unit(ostring* w, unsigned int f) :
|
||||
encoding_unit::encoding_unit(std::string* w, unsigned int f) :
|
||||
word(w), bits(0), freq(f), code(0), leaf_htr_node(NULL)
|
||||
{
|
||||
}
|
||||
|
@ -60,7 +61,7 @@ encoding_unit::~encoding_unit()
|
|||
delete word;
|
||||
}
|
||||
|
||||
ostream& operator<<(ostream& out, encoding_unit& eu)
|
||||
std::ostream& operator<<(std::ostream& out, encoding_unit& eu)
|
||||
{
|
||||
debug(out, *eu.word);
|
||||
debug(out, eu.freq);
|
||||
|
|
|
@ -51,7 +51,8 @@
|
|||
#ifndef _code_h
|
||||
#define _code_h 1
|
||||
|
||||
#include "utility/ostring.h"
|
||||
#include <string>
|
||||
|
||||
////////////////////////////////////////
|
||||
//
|
||||
////////////////////////////////////////
|
||||
|
@ -61,17 +62,17 @@ class htr_node;
|
|||
class encoding_unit
|
||||
{
|
||||
public:
|
||||
ostring* word;
|
||||
std::string* word;
|
||||
int bits;
|
||||
unsigned int freq;
|
||||
unsigned int code;
|
||||
htr_node* leaf_htr_node;
|
||||
|
||||
public:
|
||||
encoding_unit(ostring* w, unsigned int freq);
|
||||
encoding_unit(std::string* w, unsigned int freq);
|
||||
~encoding_unit();
|
||||
|
||||
friend ostream& operator <<(ostream&, encoding_unit&);
|
||||
friend std::ostream& operator <<(std::ostream&, encoding_unit&);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -310,7 +310,7 @@ void huff::compress(const buffer& uncompressed, buffer& compressed)
|
|||
void huff::decompress(buffer& compressed, buffer& uncompressed)
|
||||
{
|
||||
char* buf_base = uncompressed.get_base();
|
||||
char* str;
|
||||
const char* str;
|
||||
int str_len;
|
||||
|
||||
char rem_bits;
|
||||
|
@ -339,7 +339,7 @@ void huff::decompress(buffer& compressed, buffer& uncompressed)
|
|||
//}
|
||||
|
||||
str_len = node_ptr -> eu -> word -> size();
|
||||
str = node_ptr -> eu -> word -> get();
|
||||
str = node_ptr -> eu -> word -> c_str();
|
||||
|
||||
if ( str_len == 1 ) {
|
||||
|
||||
|
@ -379,8 +379,8 @@ void huff::decompress(buffer& compressed, buffer& uncompressed)
|
|||
uncompressed.set_content_sz(buf_base-uncompressed.get_base());
|
||||
|
||||
if ( rem_bits > 0 )
|
||||
uncompressed.put( node_ptr -> eu -> word -> get(),
|
||||
node_ptr -> eu -> word -> size()
|
||||
uncompressed.put( node_ptr -> eu -> word -> c_str(),
|
||||
node_ptr -> eu -> word -> size()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ io_status huff::cdrOut(buffer& buf)
|
|||
word_sz = e_units[i] -> word -> size();
|
||||
v_out_buf.put(char(word_sz));
|
||||
|
||||
v_out_buf.put(e_units[i] -> word -> get(), word_sz);
|
||||
v_out_buf.put(e_units[i] -> word -> c_str(), word_sz);
|
||||
v_out_buf.put(e_units[i] -> freq);
|
||||
}
|
||||
|
||||
|
|
|
@ -221,7 +221,7 @@ void trie::add(unsigned char* word, int sz, int fq)
|
|||
encoding_unit* trie::add_to_alphabet(unsigned char* word, int sz, int fq)
|
||||
{
|
||||
extend_alphabet();
|
||||
encoding_unit *x = new encoding_unit(new ostring((char*)word, sz), fq);
|
||||
encoding_unit *x = new encoding_unit(new string((char*)word, sz), fq);
|
||||
alphabet[alphabet_sz++] = x;
|
||||
return x;
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ cerr << "\n";
|
|||
static trie_node_info* y = 0;
|
||||
|
||||
static char buf[1];
|
||||
static ostring *z;
|
||||
static string *z;
|
||||
|
||||
if ( root == 0 )
|
||||
root = new trie_node(0);
|
||||
|
@ -261,7 +261,7 @@ cerr << "\n";
|
|||
y -> info.info_view.letter = j;
|
||||
|
||||
buf[0] = char(j);
|
||||
z = new ostring(buf, 1);
|
||||
z = new string(buf, 1);
|
||||
y -> info.info_view.mark = 1;
|
||||
|
||||
extend_alphabet();
|
||||
|
@ -292,7 +292,7 @@ void update_index(int ind, void* x)
|
|||
void trie::_find_leaf(trie_node* z, int& j)
|
||||
{
|
||||
trie_node_info* x = 0;
|
||||
ostring *y;
|
||||
string *y;
|
||||
|
||||
for ( int i=0; i<LANG_ALPHABET_SZ; i++ ) {
|
||||
#ifdef C_API
|
||||
|
@ -322,7 +322,7 @@ encoding_unit** trie::get_alphabet(unsigned int& a_sz)
|
|||
return alphabet;
|
||||
}
|
||||
|
||||
ostring* trie::get_word(trie_node_info* leaf)
|
||||
string* trie::get_word(trie_node_info* leaf)
|
||||
{
|
||||
static char buf[128];
|
||||
buf[127] = 0;
|
||||
|
@ -343,7 +343,7 @@ ostring* trie::get_word(trie_node_info* leaf)
|
|||
}
|
||||
|
||||
//debug(cerr, buf+i);
|
||||
return new ostring(buf+i, 127-i);
|
||||
return new string(buf+i, 127-i);
|
||||
}
|
||||
|
||||
Boolean trie::travers_to(char* str, int len,
|
||||
|
|
|
@ -130,7 +130,7 @@ protected:
|
|||
|
||||
protected:
|
||||
void collect_freqs(trie_node* rt, int level);
|
||||
ostring* get_word(trie_node_info* x);
|
||||
string* get_word(trie_node_info* x);
|
||||
|
||||
void _find_leaf(trie_node* z, int& j);
|
||||
void extend_alphabet();
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
#define _index_agent_h 1
|
||||
|
||||
#include "utility/funcs.h"
|
||||
#include "utility/ostring.h"
|
||||
#include "dynhash/data_t.h"
|
||||
|
||||
//**************************************************************
|
||||
|
|
|
@ -80,7 +80,7 @@ size_t btree_index::handler_to_inv_idx(const handler& query)
|
|||
{
|
||||
get_key_string(query);
|
||||
|
||||
data_t k(v_static_key.get(), v_static_key.size());
|
||||
data_t k(v_static_key.c_str(), v_static_key.size());
|
||||
|
||||
if ( v_idx_agent_ptr -> member(k) == false )
|
||||
throw(stringException("first_of_invlist(): key is not in btree"));
|
||||
|
|
|
@ -81,7 +81,7 @@ if ( v_static_key.get() )
|
|||
MESSAGE(cerr, "************");
|
||||
*/
|
||||
|
||||
return new data_t(v_static_key.get(), v_static_key.size());
|
||||
return new data_t(v_static_key.c_str(), v_static_key.size());
|
||||
}
|
||||
|
||||
Boolean
|
||||
|
|
|
@ -257,7 +257,7 @@ debug(cerr, k);
|
|||
throw(stringException("hash table empty"));
|
||||
}
|
||||
|
||||
i = v_tbl0 -> atoi(k.get(), k.size(), r, v_key_set_sz); // for halmphf
|
||||
i = v_tbl0 -> atoi(k.c_str(), k.size(), r, v_key_set_sz); // for halmphf
|
||||
|
||||
|
||||
if ( i < v_p1 ) {
|
||||
|
@ -275,7 +275,7 @@ debug(cerr, k);
|
|||
//i = v_tbl1 -> atoi(k, c_bit+r+1) + gv;
|
||||
//debug(cerr, c_bit+r);
|
||||
|
||||
i = v_tbl1 -> atoi(k.get(), k.size(), c_bit+r+1, v_hash_tbl_sz) + gv; // for halmphf
|
||||
i = v_tbl1 -> atoi(k.c_str(), k.size(), c_bit+r+1, v_hash_tbl_sz) + gv; // for halmphf
|
||||
|
||||
|
||||
return i % v_hash_tbl_sz;
|
||||
|
@ -422,7 +422,7 @@ fast_mphf::print_mapping(const char *key_file, int option)
|
|||
//debug(cerr, option);
|
||||
MESSAGE(cerr, "print_mapping()");
|
||||
|
||||
char string[LBUFSIZ];
|
||||
char str[LBUFSIZ];
|
||||
fstream in(key_file, ios::in);
|
||||
|
||||
if ( !in ) {
|
||||
|
@ -432,23 +432,23 @@ fast_mphf::print_mapping(const char *key_file, int option)
|
|||
char *hash_table = new char[v_hash_tbl_sz];
|
||||
for (unsigned int i = 0; i < v_hash_tbl_sz; hash_table[i++] = 0 );
|
||||
|
||||
ostring lbuf(LBUFSIZ);
|
||||
string lbuf; lbuf.reserve(LBUFSIZ);
|
||||
|
||||
|
||||
while ( in.getline(string, LBUFSIZ, '\n') ) {
|
||||
while ( in.getline(str, LBUFSIZ, '\n') ) {
|
||||
|
||||
// string[strlen(string)-1] = '\0';
|
||||
// str[strlen(str)-1] = '\0';
|
||||
|
||||
//debug(cerr, string);
|
||||
//debug(cerr, strlen(string));
|
||||
//debug(cerr, str);
|
||||
//debug(cerr, strlen(str));
|
||||
|
||||
lbuf.reset();
|
||||
lbuf.set(string, strlen(string));
|
||||
lbuf.clear();
|
||||
lbuf.assign(str, strlen(str));
|
||||
|
||||
int hash = hashTo(lbuf) ;
|
||||
|
||||
if ( option == 1 ) {
|
||||
cout << " string = " << string;
|
||||
cout << " string = " << str;
|
||||
cout << ", hash = " << hash << "\n";
|
||||
}
|
||||
|
||||
|
@ -457,7 +457,7 @@ fast_mphf::print_mapping(const char *key_file, int option)
|
|||
else
|
||||
hash_table[hash] = 1;
|
||||
|
||||
in.getline(string, LBUFSIZ, '\n');
|
||||
in.getline(str, LBUFSIZ, '\n');
|
||||
}
|
||||
|
||||
MESSAGE(cerr, "print_mapping() done");
|
||||
|
|
|
@ -54,7 +54,7 @@
|
|||
key_type* c_index::v_static_key_ptr;
|
||||
#define v_static_key (*v_static_key_ptr)
|
||||
#else
|
||||
key_type c_index::v_static_key(LBUFSIZ);
|
||||
key_type c_index::v_static_key;
|
||||
#endif
|
||||
|
||||
void c_index::init_persistent_info(persistent_info* x)
|
||||
|
@ -66,6 +66,7 @@ void c_index::init_persistent_info(persistent_info* x)
|
|||
c_index::c_index(c_code_t c_cd) : composite(c_cd), v_inv_lists_hd(NULL)
|
||||
{
|
||||
v_cmp_selector = 0;
|
||||
v_static_key.reserve(LBUFSIZ);
|
||||
}
|
||||
|
||||
oid_list_handler* c_index::operator()(int ind)
|
||||
|
@ -108,27 +109,21 @@ oid_t c_index::first_of_invlist(int ind)
|
|||
Boolean c_index::get_key_string(const handler& t) const
|
||||
{
|
||||
ostringstream out;
|
||||
int len;
|
||||
|
||||
((handler&)t) -> asciiOut(out);
|
||||
len = out.str().size();
|
||||
v_static_key.set_size(len);
|
||||
*((char *) memcpy(v_static_key.get(), out.str().c_str(), len) + len) = '\0';
|
||||
v_static_key = out.str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean c_index::get_key_string(const oid_t& t) const
|
||||
{
|
||||
v_static_key.reset();
|
||||
int len;
|
||||
v_static_key.clear();
|
||||
|
||||
ostringstream out(v_static_key.c_str());
|
||||
|
||||
ostringstream out(v_static_key.get());
|
||||
t.asciiOut(out);
|
||||
|
||||
len = out.str().size();
|
||||
v_static_key.set_size(len);
|
||||
*((char *) memcpy(v_static_key.get(), out.str().c_str(), len) + len) = '\0';
|
||||
v_static_key = out.str();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -150,13 +150,13 @@ debug(cerr, (void*)(v_mphf->operator->()));
|
|||
v_sz = (*v_mphf) -> keysetsize();
|
||||
(*v_inv_lists_hd) -> expand_space(v_sz);
|
||||
|
||||
key_type key(LBUFSIZ);
|
||||
|
||||
key_type key; key.reserve(LBUFSIZ);
|
||||
|
||||
#ifdef DEBUG
|
||||
int i = 0;
|
||||
#endif
|
||||
|
||||
while ( in >> key ) {
|
||||
while (std::getline(in, key)) {
|
||||
|
||||
oid_t key_id(c_code_t(0), 0);
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ debug(cerr, y -> v_name);
|
|||
*/
|
||||
|
||||
|
||||
return ( x -> v_name.string_LS(y -> v_name) );
|
||||
return ( x -> v_name.compare(y -> v_name) < 0);
|
||||
}
|
||||
|
||||
Boolean name_oid_eq(const void* o1, const void* o2)
|
||||
|
@ -75,7 +75,7 @@ MESSAGE(cerr, "in name_oid_eq");
|
|||
debug(cerr, x -> v_name);
|
||||
debug(cerr, y -> v_name);
|
||||
*/
|
||||
return ( x -> v_name.string_EQ(y -> v_name) );
|
||||
return ( x -> v_name.compare(y -> v_name) == 0);
|
||||
}
|
||||
|
||||
Boolean oid_ls(const void* o1, const void* o2)
|
||||
|
@ -145,15 +145,14 @@ void delete_name_oid_rec_f(const void* name_oid_ptr)
|
|||
//
|
||||
// ***************************************************
|
||||
|
||||
mark_t::mark_t(char* marks) : ostring(strlen(marks))
|
||||
mark_t::mark_t(char* marks) : string(marks)
|
||||
{
|
||||
set(marks);
|
||||
}
|
||||
|
||||
istream& operator >>(istream& in, mark_t& m)
|
||||
{
|
||||
char c ;
|
||||
char* ptr = m.get();
|
||||
const char* ptr = m.c_str();
|
||||
Boolean read_marks = false;
|
||||
|
||||
while ( in && in.get(c) ) {
|
||||
|
@ -175,7 +174,7 @@ istream& operator >>(istream& in, mark_t& m)
|
|||
|
||||
ostream& operator <<(ostream& out, mark_t& m)
|
||||
{
|
||||
out << m.get();
|
||||
out << m.c_str();
|
||||
return out ;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@
|
|||
#define _misc_h
|
||||
|
||||
#include "object/root.h"
|
||||
#include "utility/ostring.h"
|
||||
#include "storage/abs_storage.h"
|
||||
#include "object/handler.h"
|
||||
|
||||
|
@ -71,25 +70,25 @@ class name_oid_t
|
|||
public:
|
||||
name_oid_t(const char* nm, abs_storage* store = 0) : v_store(store)
|
||||
{
|
||||
v_name.set(nm);
|
||||
v_name.assign(nm);
|
||||
}
|
||||
name_oid_t(const char* nm, const oid_t& id, abs_storage* store = 0) :
|
||||
v_oid(id), v_store(store)
|
||||
{
|
||||
v_name.set(nm);
|
||||
v_name.assign(nm);
|
||||
};
|
||||
|
||||
~name_oid_t() {};
|
||||
|
||||
public:
|
||||
ostring v_name;
|
||||
string v_name;
|
||||
oid_t v_oid;
|
||||
abs_storage* v_store;
|
||||
};
|
||||
|
||||
void delete_name_oid_rec_f(const void* name_oid_ptr);
|
||||
|
||||
class mark_t : private ostring
|
||||
class mark_t : private string
|
||||
{
|
||||
public:
|
||||
mark_t(char* marks = (char*)"\t\n ");
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
/*
|
||||
* CDE - Common Desktop Environment
|
||||
*
|
||||
* Copyright (c) 1993-2012, The Open Group. All rights reserved.
|
||||
*
|
||||
* These libraries and programs are free software; you can
|
||||
* redistribute them and/or modify them under the terms of the GNU
|
||||
* Lesser General Public License as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* These libraries and programs are distributed in the hope that
|
||||
* they will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with these libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/* $XConsortium: name_oid_t.h /main/3 1996/06/11 17:22:59 cde-hal $ */
|
||||
class name_oid_t {
|
||||
|
||||
public:
|
||||
ostring name;
|
||||
oid_t v_oid;
|
||||
|
||||
name_oid_t(const char* nm, oid_t& id) : v_oid(id) {
|
||||
name.set(nm);
|
||||
};
|
||||
};
|
|
@ -52,7 +52,6 @@
|
|||
#define _long_pstring_h 1
|
||||
|
||||
#include "object/pstring.h"
|
||||
#include "utility/ostring.h"
|
||||
#include "storage/page_storage.h"
|
||||
#include "storage/chunks_index.h"
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
|
||||
void oid_list::init_persistent_info(persistent_info* x)
|
||||
{
|
||||
ostring* u = list_ptr.p;
|
||||
string* u = list_ptr.p;
|
||||
|
||||
root::init_persistent_info(x);
|
||||
|
||||
|
@ -62,7 +62,7 @@ void oid_list::init_persistent_info(persistent_info* x)
|
|||
//debug(cerr, (void*)this);
|
||||
//debug(cerr, my_oid());
|
||||
|
||||
char* w = 0;
|
||||
const char* w = 0;
|
||||
int v= 0;
|
||||
|
||||
//MESSAGE(cerr, "oid_list::init_persistent_info(), new object case");
|
||||
|
@ -70,7 +70,7 @@ void oid_list::init_persistent_info(persistent_info* x)
|
|||
//debug(cerr, (void*)list_ptr.p);
|
||||
|
||||
if (u) {
|
||||
w = u -> get();
|
||||
w = u -> c_str();
|
||||
v = u -> size();
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ void oid_list::init_data_member(int leng)
|
|||
}
|
||||
|
||||
list_ptr.loc = 0; // to please purify
|
||||
list_ptr.p = new ostring(ptr, char_leng);
|
||||
list_ptr.p = new string(ptr, char_leng);
|
||||
|
||||
//MESSAGE(cerr, "oid_list::init_data_member(int leng)");
|
||||
//debug(cerr, (void*)this);
|
||||
|
@ -170,8 +170,6 @@ debug(cerr, int(list_ptr.loc));
|
|||
debug(cerr, int(&list_ptr.loc));
|
||||
*/
|
||||
|
||||
Boolean ok;
|
||||
|
||||
int extra_char_leng = extra_oids * OID_T_SZ;
|
||||
|
||||
if ( get_mode(PERSISTENT) == true ) {
|
||||
|
@ -189,18 +187,15 @@ debug(cerr, int(&list_ptr.loc));
|
|||
}
|
||||
|
||||
delete [] ptr;
|
||||
|
||||
ok = true;
|
||||
|
||||
} else {
|
||||
ok = list_ptr.p -> expand( extra_char_leng );
|
||||
list_ptr.p -> resize( extra_char_leng );
|
||||
}
|
||||
|
||||
v_sz += extra_oids;
|
||||
|
||||
set_mode(UPDATE, true);
|
||||
|
||||
return ok;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -275,7 +270,7 @@ debug(cerr, int(list_ptr.p));
|
|||
if ( list_ptr.p == 0 )
|
||||
throw(stringException("zero list_ptr.p value"));
|
||||
|
||||
memcpy(z, list_ptr.p -> get() + offset, OID_T_SZ);
|
||||
memcpy(z, list_ptr.p -> c_str() + offset, OID_T_SZ);
|
||||
|
||||
}
|
||||
//MESSAGE(cerr, "oid_list::operator() done");
|
||||
|
@ -363,7 +358,7 @@ oid_list::update_component(int index, const oid_t& new_oid)
|
|||
if ( list_ptr.p == 0 )
|
||||
throw(stringException("zero list_ptr.p value"));
|
||||
|
||||
list_ptr.p -> update(z, OID_T_SZ, (index-1)*OID_T_SZ);
|
||||
list_ptr.p -> replace((index-1)*OID_T_SZ, OID_T_SZ, z);
|
||||
|
||||
}
|
||||
//MESSAGE(cerr, "oid_list::update_component() done");
|
||||
|
@ -435,8 +430,8 @@ io_status oid_list::asciiIn(istream& in)
|
|||
|
||||
} else {
|
||||
delete list_ptr.p;
|
||||
list_ptr.p = new ostring(0);
|
||||
list_ptr.p -> set(oid_array, v_sz);
|
||||
list_ptr.p = new string(0);
|
||||
list_ptr.p -> assign(oid_array, v_sz);
|
||||
}
|
||||
|
||||
delete [] oid_array;
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
#ifndef _oid_list_h
|
||||
#define _oid_list_h 1
|
||||
|
||||
#include "utility/ostring.h"
|
||||
#include "dstr/dlist.h"
|
||||
#include "dstr/dlist_void_ptr_cell.h"
|
||||
#include "object/oid.h"
|
||||
|
@ -71,7 +70,7 @@ protected:
|
|||
|
||||
union {
|
||||
mmdb_pos_t loc;
|
||||
ostring* p;
|
||||
string* p;
|
||||
} list_ptr;
|
||||
|
||||
protected:
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
#define _object_dict 1
|
||||
|
||||
#include "dstr/bset.h"
|
||||
#include "utility/ostring.h"
|
||||
#include "object/handler.h"
|
||||
|
||||
#include "mgrs/template_mgr.h"
|
||||
|
|
|
@ -4,7 +4,7 @@ noinst_LTLIBRARIES = libutility.la
|
|||
|
||||
libutility_la_CXXFLAGS = -DPORTABLE_DB -I..
|
||||
|
||||
libutility_la_SOURCES = funcs.C ostring.C pm_random.C \
|
||||
libutility_la_SOURCES = funcs.C pm_random.C \
|
||||
atoi_pearson.C xtime.C buffer.C \
|
||||
atoi_larson.C atomic_lock.C rw_lock.C \
|
||||
atoi_fast.C filter.C mmdb_exception.C \
|
||||
|
|
|
@ -98,7 +98,7 @@ union u_tag {
|
|||
|
||||
int atoi_fast::atoi(const key_type& k, int offset) const
|
||||
{
|
||||
char* string = k.get();
|
||||
const char* string = k.c_str();
|
||||
int l = k.size();
|
||||
return atoi((const char*)string, l, offset, 0);
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ atoi_larson::atoi(const char* str, int sz, int, int rang) const
|
|||
int
|
||||
atoi_larson::atoi(const key_type& k, int) const
|
||||
{
|
||||
char* string = k.get();
|
||||
const char* string = k.c_str();
|
||||
int l = k.size();
|
||||
|
||||
unsigned int sum = 0;
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#else
|
||||
#include <values.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include "key.h"
|
||||
|
||||
// Based on Larson's algorithm presented in CACM ???.
|
||||
|
|
|
@ -129,7 +129,7 @@ union u_tag {
|
|||
|
||||
int atoi_pearson::atoi(const key_type& k, int offset) const
|
||||
{
|
||||
char* string = k.get();
|
||||
const char* string = k.c_str();
|
||||
int l = k.size();
|
||||
return atoi((const char*)string, l, offset, 0);
|
||||
}
|
||||
|
|
|
@ -45,8 +45,8 @@
|
|||
#ifndef _key_h
|
||||
#define _key_h 1
|
||||
|
||||
#include "utility/ostring.h"
|
||||
#include <string>
|
||||
|
||||
typedef ostring key_type;
|
||||
typedef std::string key_type;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,284 +0,0 @@
|
|||
/*
|
||||
* CDE - Common Desktop Environment
|
||||
*
|
||||
* Copyright (c) 1993-2012, The Open Group. All rights reserved.
|
||||
*
|
||||
* These libraries and programs are free software; you can
|
||||
* redistribute them and/or modify them under the terms of the GNU
|
||||
* Lesser General Public License as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* These libraries and programs are distributed in the hope that
|
||||
* they will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with these libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: ostring.cc /main/3 1996/06/11 17:38:07 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "utility/ostring.h"
|
||||
|
||||
#ifdef C_API
|
||||
char* ostring::input_buf = 0;
|
||||
#else
|
||||
char ostring::input_buf[LBUFSIZ];
|
||||
#endif
|
||||
|
||||
ostring::ostring() : v_sz(0), v_allo_sz(1)
|
||||
{
|
||||
v_p = new char[1];
|
||||
}
|
||||
|
||||
ostring::ostring(const int i) : v_sz(0), v_allo_sz(i+1)
|
||||
{
|
||||
v_p = new char[i+1];
|
||||
}
|
||||
|
||||
ostring::ostring(char* x, const int i)
|
||||
{
|
||||
int w = i;
|
||||
|
||||
if ( w == -1 ) {
|
||||
w = strlen(x);
|
||||
}
|
||||
|
||||
v_sz = w;
|
||||
v_allo_sz = w+1;
|
||||
|
||||
v_p = new char[w+1];
|
||||
memcpy(v_p, x, w);
|
||||
v_p[w] = 0;
|
||||
}
|
||||
|
||||
ostring::ostring(const ostring& s) :
|
||||
v_sz(s.v_sz), v_allo_sz(s.v_allo_sz)
|
||||
{
|
||||
v_p = new char[v_allo_sz];
|
||||
memcpy(v_p, s.v_p, v_sz);
|
||||
v_p[v_sz] = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
ostring::~ostring()
|
||||
{
|
||||
delete v_p;
|
||||
}
|
||||
*/
|
||||
|
||||
Boolean ostring::set(const char* x, int l)
|
||||
{
|
||||
expand(l+1);
|
||||
|
||||
memcpy(v_p, x, l);
|
||||
v_p[l] = 0;
|
||||
v_sz = l;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Boolean ostring::set(const char* x)
|
||||
{
|
||||
return set(x, strlen(x));
|
||||
}
|
||||
|
||||
void ostring::reset()
|
||||
{
|
||||
v_sz = 0;
|
||||
}
|
||||
|
||||
void ostring::set_size(const int s)
|
||||
{
|
||||
v_sz = s;
|
||||
v_p[v_sz] = 0;
|
||||
}
|
||||
*/
|
||||
|
||||
/********************************************/
|
||||
// set alloc_sz to at least new_alloc_sz bytes
|
||||
/********************************************/
|
||||
Boolean ostring::expand(const int new_alloc_sz, Boolean pre_zero)
|
||||
{
|
||||
if ( new_alloc_sz > v_allo_sz ) {
|
||||
v_allo_sz = new_alloc_sz+1;
|
||||
char* new_p = new char[v_allo_sz];
|
||||
|
||||
if ( pre_zero == true )
|
||||
memset(new_p, char(0), v_allo_sz);
|
||||
|
||||
if ( v_p ) {
|
||||
memcpy(new_p, v_p, v_sz);
|
||||
delete [] v_p;
|
||||
}
|
||||
|
||||
v_p = new_p;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
char* ostring::acquire()
|
||||
{
|
||||
v_allo_sz = v_sz = 0;
|
||||
char *x = v_p;
|
||||
v_p = 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
Boolean ostring::append(const char* x, int l)
|
||||
{
|
||||
expand(v_sz+l+1);
|
||||
|
||||
memcpy(v_p+v_sz, x, l);
|
||||
v_sz += l;
|
||||
v_p[v_sz] = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
Boolean ostring::update(const char* x, int l, int offset)
|
||||
{
|
||||
if ( offset + l > v_sz ) {
|
||||
MESSAGE(cerr, "update(): char chunk too small");
|
||||
throw(boundaryException(0, v_sz, offset+l));
|
||||
}
|
||||
|
||||
memcpy(v_p+offset, x, l);
|
||||
return true;
|
||||
}
|
||||
|
||||
int ostring::substr(ostring& s)
|
||||
{
|
||||
if ( v_p == 0 || s.v_p == 0 )
|
||||
return -1;
|
||||
|
||||
char* sub_p = strstr(v_p, s.v_p);
|
||||
|
||||
if ( sub_p == 0 )
|
||||
return -1;
|
||||
else
|
||||
return (int)(sub_p - v_p);
|
||||
}
|
||||
|
||||
/*
|
||||
int ostring::size() const
|
||||
{
|
||||
return v_sz;
|
||||
}
|
||||
|
||||
int ostring::alloc_size() const
|
||||
{
|
||||
return v_allo_sz;
|
||||
}
|
||||
*/
|
||||
|
||||
ostring& ostring::operator +(ostring& s)
|
||||
{
|
||||
int l1 = v_sz;
|
||||
int l2 = s.v_sz;
|
||||
|
||||
ostring *new_ostring = new ostring(l1+l2);
|
||||
|
||||
int i;
|
||||
for ( i = 0; i<l1; (*new_ostring).v_p[i] = s.v_p[i] ) i++;
|
||||
for ( i = 0; i<l2; (*new_ostring).v_p[l1 + i] = s.v_p[i] ) i++;
|
||||
|
||||
return *new_ostring;
|
||||
}
|
||||
|
||||
Boolean ostring::string_LS(ostring& y) const
|
||||
{
|
||||
char* x_str = this -> get() ;
|
||||
char* y_str = y.get() ;
|
||||
|
||||
int x_sz = this -> size() ;
|
||||
int y_sz = y.size() ;
|
||||
|
||||
if ( x_sz == y_sz ) {
|
||||
if ( memcmp(x_str, y_str, x_sz ) < 0 )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
} else {
|
||||
|
||||
int min = MIN(x_sz, y_sz);
|
||||
|
||||
for ( int i=0; i<min; i++ ) {
|
||||
if ( x_str[i] < y_str[i] )
|
||||
return true;
|
||||
else
|
||||
if ( x_str[i] > y_str[i] )
|
||||
return false;
|
||||
}
|
||||
if ( x_sz < y_sz )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Boolean ostring::string_EQ(ostring& y) const
|
||||
{
|
||||
if ( this -> size() == y.size() &&
|
||||
memcmp(this -> get(), y.get(), this -> size() ) == 0
|
||||
)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
ostream& operator <<(ostream& s, const ostring& o)
|
||||
{
|
||||
if ( o.v_p ) {
|
||||
//s << o.v_sz << ":";
|
||||
for ( int i=0; i<o.v_sz; i++ )
|
||||
// if ( isprint(o.v_p[i]) )
|
||||
s << o.v_p[i];
|
||||
// else
|
||||
// s << int(o.v_p[i]);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
istream& operator >>(istream& s, ostring& o)
|
||||
{
|
||||
s.getline( o.input_buf, LBUFSIZ );
|
||||
o.set(o.input_buf);
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
ostring* ostring::operator+= (ostring* )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
ostring* ostring::concate_with(...)
|
||||
{
|
||||
return 0 ;
|
||||
}
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
/*
|
||||
* CDE - Common Desktop Environment
|
||||
*
|
||||
* Copyright (c) 1993-2012, The Open Group. All rights reserved.
|
||||
*
|
||||
* These libraries and programs are free software; you can
|
||||
* redistribute them and/or modify them under the terms of the GNU
|
||||
* Lesser General Public License as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* These libraries and programs are distributed in the hope that
|
||||
* they will be useful, but WITHOUT ANY WARRANTY; without even the
|
||||
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU Lesser General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with these libraries and programs; if not, write
|
||||
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
|
||||
* Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
/*
|
||||
* $XConsortium: ostring.h /main/3 1996/06/11 17:38:12 cde-hal $
|
||||
*
|
||||
* Copyright (c) 1992 HaL Computer Systems, Inc. All rights reserved.
|
||||
* UNPUBLISHED -- rights reserved under the Copyright Laws of the United
|
||||
* States. Use of a copyright notice is precautionary only and does not
|
||||
* imply publication or disclosure.
|
||||
*
|
||||
* This software contains confidential information and trade secrets of HaL
|
||||
* Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
|
||||
* without the prior express written permission of HaL Computer Systems, Inc.
|
||||
*
|
||||
* RESTRICTED RIGHTS LEGEND
|
||||
* Use, duplication, or disclosure by the Government is subject to
|
||||
* restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
|
||||
* Technical Data and Computer Software clause at DFARS 252.227-7013.
|
||||
* HaL Computer Systems, Inc.
|
||||
* 1315 Dell Avenue, Campbell, CA 95008
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _ostring_h
|
||||
#define _ostring_h 1
|
||||
|
||||
#include "utility/funcs.h"
|
||||
|
||||
class ostring {
|
||||
|
||||
public:
|
||||
ostring();
|
||||
ostring(const int chunk_size);
|
||||
ostring(char* str, const int str_sz = -1); // -1 means take strlen(str)
|
||||
ostring(const ostring&);
|
||||
virtual ~ostring() { delete [] v_p; };
|
||||
|
||||
// length of the string
|
||||
int size() const { return v_sz; };
|
||||
// length of the allocated chunk
|
||||
int alloc_size() const { return v_allo_sz; };
|
||||
|
||||
ostring& operator +(ostring&); // merge of two strings
|
||||
int substr(ostring&); // substring matching
|
||||
|
||||
// set string to content x
|
||||
Boolean set(const char* x) { return set(x, strlen(x)); };
|
||||
|
||||
Boolean set(const char* x, int i); // set string to content x with length i
|
||||
Boolean append(const char* x, int l); // append a string x of length i
|
||||
Boolean update(const char* x, int l, int offset); // update a substring x of length i at 'offset'. offset + l should be sz
|
||||
|
||||
//set alloc_sz to at least new_alloc_sz bytes
|
||||
// pre_zero = true -> zero new space before copy old content over
|
||||
Boolean expand(const int, Boolean pre_zero = false);
|
||||
|
||||
void reset() { v_sz = 0; };
|
||||
void set_size(const int s) { v_sz = s; v_p[v_sz] = 0; };
|
||||
|
||||
char* get() const { return v_p; }; // get char pointer p
|
||||
|
||||
char* acquire() ; // return what is pointed at by p and reset
|
||||
// alloc_sz, sz, and p to 0;
|
||||
|
||||
// append x to this and return this.
|
||||
ostring* operator+= (ostring* x);
|
||||
|
||||
// concate all ostring arguments (ostring* 's) to this and return this.
|
||||
ostring* concate_with(...);
|
||||
|
||||
Boolean string_LS(ostring&) const;
|
||||
Boolean string_EQ(ostring&) const;
|
||||
|
||||
friend ostream& operator <<(ostream&, const ostring&);
|
||||
friend istream& operator >>(istream&, ostring&);
|
||||
|
||||
protected:
|
||||
char *v_p; // memory chunk pointer
|
||||
int v_sz; // string size
|
||||
int v_allo_sz; // allocated memory chunk size
|
||||
|
||||
#ifdef C_API
|
||||
static char* input_buf;
|
||||
|
||||
friend void initialize_MMDB();
|
||||
friend void quit_MMDB();
|
||||
#else
|
||||
static char input_buf[LBUFSIZ];
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue