Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / base / String.cc
index 666e79a..be0bb64 100644 (file)
@@ -17,6 +17,8 @@
 #include "zypp/base/String.h"
 #include "zypp/base/LogTools.h"
 
+#include "zypp/TriBool.h"
+
 using std::string;
 
 ///////////////////////////////////////////////////////////////////
@@ -86,6 +88,13 @@ namespace zypp
                );
     }
 
+    TriBool strToTriBool( const C_Str & str )  // from TriBool.h
+    {
+      if ( strToTrue( str ) )  return true;
+      if ( !strToFalse( str ) )        return false;
+      return indeterminate;
+    }
+
     ///////////////////////////////////////////////////////////////////
     // Hexencode
     ///////////////////////////////////////////////////////////////////
@@ -164,11 +173,15 @@ namespace zypp
      **      FUNCTION TYPE : std::string
     */
     std::string toLower( const std::string & s )
+    { return toLower( std::string(s) ); }
+
+    std::string toLower( std::string && s )
     {
-      if ( s.empty() )
-        return s;
+      std::string ret( std::move(s) );
+
+      if ( ret.empty() )
+        return ret;
 
-      std::string ret( s );
       for ( std::string::size_type i = 0; i < ret.length(); ++i )
         {
           if ( isupper( ret[i] ) )
@@ -183,11 +196,15 @@ namespace zypp
      **      FUNCTION TYPE : std::string
     */
     std::string toUpper( const std::string & s )
+    { return toUpper( std::string(s) ); }
+
+    std::string toUpper( std::string && s )
     {
-      if ( s.empty() )
-        return s;
+      std::string ret( std::move(s) );
+
+      if ( ret.empty() )
+        return ret;
 
-      std::string ret( s );
       for ( std::string::size_type i = 0; i < ret.length(); ++i )
         {
           if ( islower( ret[i] ) )
@@ -202,29 +219,36 @@ namespace zypp
      **      FUNCTION TYPE : std::string
     */
     std::string trim( const std::string & s, const Trim trim_r )
+    { return trim( std::string(s), trim_r ); }
+
+    std::string trim( std::string && s, const Trim trim_r )
     {
-      if ( s.empty() || trim_r == NO_TRIM )
-        return s;
+      std::string ret( std::move(s) );
 
-      std::string ret( s );
+      if ( ret.empty() || trim_r == NO_TRIM )
+        return ret;
 
       if ( trim_r & L_TRIM )
-        {
-          std::string::size_type p = ret.find_first_not_of( " \t\n" );
-          if ( p == std::string::npos )
-            return std::string();
-
-          ret = ret.substr( p );
-        }
+      {
+       std::string::size_type p = ret.find_first_not_of( " \t\n" );
+       if ( p == std::string::npos )
+       {
+         ret.clear();
+         return ret;
+       }
+       ret.erase( 0, p );
+      }
 
       if ( trim_r & R_TRIM )
-        {
-          std::string::size_type p = ret.find_last_not_of( " \t\n" );
-          if ( p == std::string::npos )
-            return std::string();
-
-          ret = ret.substr( 0, p+1 );
-        }
+      {
+       std::string::size_type p = ret.find_last_not_of( " \t\n" );
+       if ( p == std::string::npos )
+       {
+         ret.clear();
+         return ret;
+       }
+       ret = ret.erase( p+1 );
+      }
 
       return ret;
     }