Author: wyoung
Date: Tue Nov 20 04:04:40 2007
New Revision: 1867
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=1867&view=rev
Log:
- Removed string_util module. It had 5 functions in it, only two of
which were actually used within the library, and each of those were
used in only one place! Made those functions methods of the classes
that used them. (If we later find out that end user code uses any of
these, we can stick 'em in String or SQLTypeAdapter as public methods,
as appropriate.)
- Renamed strip_all_blanks() to String::strip_leading_blanks(),
reflecting its actual effect.
- Rewrote strip_leading_blanks() while in there. Unless std::string
on your platform is unusually clever, it was an O(N^2 / 2) algorithm
before. Now it's O(N) unless std::string's is incredibly stupid, in
which case it'll be O(N^2 / 2) again, so no harm.
Removed:
trunk/lib/string_util.cpp
trunk/lib/string_util.h
Modified:
trunk/lib/field_names.cpp
trunk/lib/field_names.h
trunk/lib/mystring.h
trunk/mysql++.bkl
Modified: trunk/lib/field_names.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/field_names.cpp?rev=1867&r1=1866&r2=1867&view=diff
==============================================================================
--- trunk/lib/field_names.cpp (original)
+++ trunk/lib/field_names.cpp Tue Nov 20 04:04:40 2007
@@ -28,8 +28,6 @@
#include "common.h"
#include "field_names.h"
-#include "string_util.h"
-
#include "result.h"
namespace mysqlpp {
Modified: trunk/lib/field_names.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/field_names.h?rev=1867&r1=1866&r2=1867&view=diff
==============================================================================
--- trunk/lib/field_names.h (original)
+++ trunk/lib/field_names.h Tue Nov 20 04:04:40 2007
@@ -96,6 +96,13 @@
private:
void init(const ResUse* res);
+ void str_to_lwr(std::string& s) const
+ {
+ std::string::iterator it;
+ for (it = s.begin(); it != s.end(); ++it) {
+ *it = tolower(*it);
+ }
+ }
};
} // end namespace mysqlpp
Modified: trunk/lib/mystring.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/mystring.h?rev=1867&r1=1866&r2=1867&view=diff
==============================================================================
--- trunk/lib/mystring.h (original)
+++ trunk/lib/mystring.h Tue Nov 20 04:04:40 2007
@@ -35,7 +35,6 @@
#include "exceptions.h"
#include "null.h"
#include "refcounted.h"
-#include "string_util.h"
#include <string>
#include <stdlib.h>
@@ -328,6 +327,25 @@
/// \brief Return number of characters in string
size_type size() const { return length(); }
+ /// \brief Returns a copy of our internal string without leading
+ /// blanks.
+ void strip_leading_blanks(std::string& s) const
+ {
+ const char* pc = data();
+ if (pc) {
+ size_type n = length();
+ while (n && (*pc == ' ')) {
+ ++pc;
+ --n;
+ }
+
+ s.assign(pc, n);
+ }
+ else {
+ s.clear();
+ }
+ }
+
/// \brief Copies this object's data into a C++ string.
///
/// If you know the data doesn't contain null characters (i.e. it's
@@ -610,8 +628,8 @@
Type
String::conv(Type) const
{
- std::string strbuf(data(), length());
- strip_all_blanks(strbuf);
+ std::string strbuf;
+ strip_leading_blanks(strbuf);
std::string::size_type len = strbuf.size();
const char* str = strbuf.data();
const char* end = str;
Removed: trunk/lib/string_util.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/string_util.cpp?rev=1866&view=auto
==============================================================================
--- trunk/lib/string_util.cpp (original)
+++ trunk/lib/string_util.cpp (removed)
@@ -1,96 +1,0 @@
-/***********************************************************************
- string_util.cpp - Implements utility functions for manipulating
- C++ strings.
-
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999, 2000 and 2001 by
- MySQL AB, and (c) 2004, 2005 by Educational Technology Resources, Inc.
- Others may also hold copyrights on code in this file. See the CREDITS
- file in the top directory of the distribution for details.
-
- This file is part of MySQL++.
-
- MySQL++ is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- MySQL++ is distributed in the hope that it 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 MySQL++; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
- USA
-***********************************************************************/
-
-#include "string_util.h"
-
-namespace mysqlpp {
-
-void strip(std::string& s)
-{
- size_t i, j = s.size() - 1;
- if (!s.size()) {
- return;
- }
- for (i = 0; s[i] == ' '; i++) ;
- if (i) {
- s.erase(0, i);
- }
- j = s.size();
- if (!j) {
- return;
- }
- j--;
- for (i = j; i && s[i] == ' '; i--) ;
- if (i != j) {
- s.erase(i + 1, static_cast<size_t> (-1));
- }
-}
-
-
-void
-str_to_upr(std::string& s)
-{
- for (std::string::size_type i = 0; i < s.length(); ++i) {
- s[i] = toupper(s[i]);
- }
-}
-
-
-void
-str_to_lwr(std::string& s)
-{
- for (std::string::size_type i = 0; i < s.length(); ++i) {
- s[i] = tolower(s[i]);
- }
-}
-
-
-void
-strip_all_blanks(std::string& s)
-{
- for (std::string::size_type i = 0; i < s.length(); ++i) {
- if (s[i] == ' ') {
- s.erase(i, 1);
- --i;
- }
- }
-}
-
-
-void
-strip_all_non_num(std::string& s)
-{
- for (std::string::size_type i = 0; i < s.length(); ++i) {
- if (!isdigit(s[i])) {
- s.erase(i, 1);
- --i;
- }
- }
-}
-
-} // end namespace mysqlpp
-
Removed: trunk/lib/string_util.h
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/string_util.h?rev=1866&view=auto
==============================================================================
--- trunk/lib/string_util.h (original)
+++ trunk/lib/string_util.h (removed)
@@ -1,56 +1,0 @@
-/// \file string_util.h
-/// \brief Declares string-handling utility functions used within
-/// the library.
-
-/***********************************************************************
- Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2007 by Educational Technology Resources, Inc. Others may
- also hold copyrights on code in this file. See the CREDITS file in
- the top directory of the distribution for details.
-
- This file is part of MySQL++.
-
- MySQL++ is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- MySQL++ is distributed in the hope that it 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 MySQL++; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
- USA
-***********************************************************************/
-
-#ifndef MYSQLPP_STRING_UTIL_H
-#define MYSQLPP_STRING_UTIL_H
-
-#include "common.h"
-
-#include <string>
-
-namespace mysqlpp {
-
-/// \brief Strips blanks at left and right ends
-MYSQLPP_EXPORT extern void strip(std::string& s);
-
-/// \brief Changes case of string to upper
-MYSQLPP_EXPORT extern void str_to_upr(std::string& s);
-
-/// \brief Changes case of string to lower
-MYSQLPP_EXPORT extern void str_to_lwr(std::string& s);
-
-/// \brief Removes all blanks
-MYSQLPP_EXPORT extern void strip_all_blanks(std::string& s);
-
-/// \brief Removes all non-numerics
-MYSQLPP_EXPORT extern void strip_all_non_num(std::string& s);
-
-} // end namespace mysqlpp
-
-#endif
-
Modified: trunk/mysql++.bkl
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/mysql%2B%2B.bkl?rev=1867&r1=1866&r2=1867&view=diff
==============================================================================
--- trunk/mysql++.bkl (original)
+++ trunk/mysql++.bkl Tue Nov 20 04:04:40 2007
@@ -58,7 +58,6 @@
lib/result.cpp
lib/row.cpp
lib/stadapter.cpp
- lib/string_util.cpp
lib/tcp_connection.cpp
lib/transaction.cpp
lib/type_info.cpp
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits