Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / base / String.cc
index 47ef8b1..be0bb64 100644 (file)
@@ -173,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] ) )
@@ -192,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] ) )
@@ -211,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;
     }
@@ -373,91 +388,6 @@ namespace zypp
       return std::string( buf.begin(), buf.end() );
     }
 
-
-    std::string bEscape( std::string str_r, const C_Str & special_r )
-    {
-      if ( str_r.empty() )
-       return str_r;
-
-      if ( str_r.find_first_of( special_r ) == std::string::npos
-       && ( ::strchr( special_r.c_str(), '\\' ) ||  !::strchr( str_r.c_str(), '\\' ) ) )
-       return str_r;
-
-      Str buf;
-      for_( s, str_r.c_str(), s+str_r.size() )
-      {
-       if ( *s == '\\' || ::strchr( special_r.c_str(), *s ) )
-         buf << '\\';
-       buf << *s;
-      }
-      return buf;
-    }
-
-    #define RXSPECIALCHARS "\\.*+?^$[()|{"
-
-    std::string rxEscapeStr( std::string str_r )
-    {
-      return bEscape( std::move(str_r), RXSPECIALCHARS );
-    }
-
-    std::string rxEscapeGlob( std::string str_r )
-    {
-      if ( str_r.empty() )
-       return str_r;
-
-      if ( str_r.find_first_of( RXSPECIALCHARS ) == std::string::npos )
-       return str_r;
-
-      Str buf;
-      for_( s, str_r.c_str(), s+str_r.size() )
-      {
-       if ( *s == '\\' )       // + next char literally
-       {
-         buf << '\\';
-         if ( *(s+1) ) { ++s; buf << *s; }
-       }
-       else if ( *s == '?' )   // translate
-       {
-         buf << '.';
-       }
-       else if ( *s == '*' )   // translate
-       {
-         buf << ".*";
-       }
-       else if ( *s == '[' )   // character class if closing ] is found, else literally
-       {
-         const char * e = s+1;
-         if ( *e == '^' || *e == '!' ) // negated cclass
-           ++e;
-         if ( *e == ']' )              // ] in cclass
-           ++e;
-         while ( *e && *e != ']' )     // ...to ] or \0
-           ++e;
-         if ( *e ) // on closing ']'
-         {
-           ++s;  buf << '[' << (*s == '!' ? '^' : *s );
-           while ( ++s != e )
-             buf << *s;
-           buf << ']';
-         }
-         else
-         {
-           buf << "\\[";
-         }
-       }
-       else if ( ::strchr( RXSPECIALCHARS, *s ) )      // escape
-       {
-         buf << '\\' << *s;
-       }
-       else
-       {
-         buf << *s;
-       }
-      }
-      return buf;
-    }
-
-
     std::string getline( std::istream & str, const Trim trim_r )
     {
       return trim( receiveUpTo( str, '\n' ), trim_r );