]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Move substring method to VAPI file, handle negative and out of bounds
authorJürg Billeter <j@bitron.ch>
Tue, 16 Dec 2008 08:27:59 +0000 (08:27 +0000)
committerJürg Billeter <juergbi@src.gnome.org>
Tue, 16 Dec 2008 08:27:59 +0000 (08:27 +0000)
2008-12-16  Jürg Billeter  <j@bitron.ch>

* gobject/valaccodebasemodule.vala:
* gobject/valaccodemethodcallmodule.vala:
* vapi/glib-2.0.vapi:

Move substring method to VAPI file, handle negative and out of
bounds values, fixes bug 443524

svn path=/trunk/; revision=2175

ChangeLog
gobject/valaccodebasemodule.vala
gobject/valaccodemethodcallmodule.vala
vapi/glib-2.0.vapi

index 2400d0dd63cc50420fba213cbdd2bff7da942655..acd0c47e194aaaa23d0c4d353875b7a271fd43f8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-12-16  Jürg Billeter  <j@bitron.ch>
+
+       * gobject/valaccodebasemodule.vala:
+       * gobject/valaccodemethodcallmodule.vala:
+       * vapi/glib-2.0.vapi:
+
+       Move substring method to VAPI file, handle negative and out of
+       bounds values, fixes bug 443524
+
 2008-12-16  Jürg Billeter  <j@bitron.ch>
 
        * vapi/packages/gnome-keyring-1/:
index d8773136c5de7d09fd643868d9bf228938abecff..43597cc9f4aff3a2ff069cb2c4d6ee78b512190f 100644 (file)
@@ -120,8 +120,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
        public Interface map_type;
        public TypeSymbol dbus_object_type;
 
-       public Method substring_method;
-
        public bool in_plugin = false;
        public string module_init_param_name;
        
@@ -566,7 +564,6 @@ public class Vala.CCodeBaseModule : CCodeModule {
                float_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("float"));
                double_type = new ValueType ((TypeSymbol) root_symbol.scope.lookup ("double"));
                string_type = new ObjectType ((Class) root_symbol.scope.lookup ("string"));
-               substring_method = (Method) string_type.data_type.scope.lookup ("substring");
 
                var glib_ns = root_symbol.scope.lookup ("GLib");
 
index 00eece34c735b93cfe5fe4442ba0f511a427d09e..cba212ee519f5257605537cdfc7a6ad1b0e7fa96 100644 (file)
@@ -460,34 +460,6 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                        ccomma.append_expression (new CCodeConditionalExpression (ccheck, czero, new CCodeConstant ("NULL")));
                        ccomma.append_expression (new CCodeAssignment (head.get_array_length_cexpression (ma.inner, 1), temp_ref));
 
-                       expr.ccodenode = ccomma;
-               } else if (m == substring_method) {
-                       var temp_decl = get_temp_variable (string_type);
-                       var temp_ref = new CCodeIdentifier (temp_decl.name);
-
-                       temp_vars.insert (0, temp_decl);
-
-                       Gee.List<CCodeExpression> args = ccall.get_arguments ();
-
-                       var coffsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_offset_to_pointer"));
-                       // full string
-                       coffsetcall.add_argument (args[0]);
-                       // offset
-                       coffsetcall.add_argument (args[1]);
-
-                       var coffsetcall2 = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_offset_to_pointer"));
-                       coffsetcall2.add_argument (temp_ref);
-                       // len
-                       coffsetcall2.add_argument (args[2]);
-
-                       var cndupcall = new CCodeFunctionCall (new CCodeIdentifier ("g_strndup"));
-                       cndupcall.add_argument (temp_ref);
-                       cndupcall.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.MINUS, coffsetcall2, temp_ref));
-
-                       var ccomma = new CCodeCommaExpression ();
-                       ccomma.append_expression (new CCodeAssignment (temp_ref, coffsetcall));
-                       ccomma.append_expression (cndupcall);
-
                        expr.ccodenode = ccomma;
                }
        }
index 4242e67adcfa90da8816e99ae5c1afb3912ba288..4085e429cd2e6d7751137c193c7a0239896e33b9 100644 (file)
@@ -7,16 +7,20 @@
  * 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.
-
+ *
  * This library 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 this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
  *
+ * As a special exception, if you use inline functions from this file, this
+ * file does not by itself cause the resulting executable to be covered by
+ * the GNU Lesser General Public License.
+ * 
  * Author:
  *     Jürg Billeter <j@bitron.ch>
  *     Raffaele Sandrini <rasa@gmx.ch>
@@ -712,8 +716,6 @@ public class string {
        public int scanf (...);
        [CCode (cname = "g_strconcat")]
        public string concat (string string2, ...);
-       [CCode (cname = "g_strndup")]
-       public string ndup (ulong n); /* FIXME: only UTF-8 */
        [CCode (cname = "g_strescape")]
        public string escape (string exceptions);
        [CCode (cname = "g_strcompress")]
@@ -800,8 +802,25 @@ public class string {
        [CCode (cname = "g_strcanon")]
        public void canon (string valid_chars, char substitutor);
 
-       /* internal method */
-       public string substring (long offset, long len);
+       // n is size in bytes, not length in characters
+       [CCode (cname = "g_strndup")]
+       public string ndup (size_t n);
+
+       public string substring (long offset, long len = -1) {
+               long string_length = this.len ();
+               if (offset < 0) {
+                       offset = string_length + offset;
+                       GLib.warn_if_fail (offset >= 0);
+               } else {
+                       GLib.warn_if_fail (offset <= string_length);
+               }
+               if (len < 0) {
+                       len = string_length - offset;
+               }
+               GLib.warn_if_fail (offset + len <= string_length);
+               weak string start = this.offset (offset);
+               return start.ndup (((char*) start.offset (len)) - ((char*) start));
+       }
 
        public bool contains (string needle) {
                return this.str (needle) != null;