vala r2175 - in trunk: . gobject vapi



Author: juergbi
Date: Tue Dec 16 08:27:59 2008
New Revision: 2175
URL: http://svn.gnome.org/viewvc/vala?rev=2175&view=rev

Log:
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


Modified:
   trunk/ChangeLog
   trunk/gobject/valaccodebasemodule.vala
   trunk/gobject/valaccodemethodcallmodule.vala
   trunk/vapi/glib-2.0.vapi

Modified: trunk/gobject/valaccodebasemodule.vala
==============================================================================
--- trunk/gobject/valaccodebasemodule.vala	(original)
+++ trunk/gobject/valaccodebasemodule.vala	Tue Dec 16 08:27:59 2008
@@ -120,8 +120,6 @@
 	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 @@
 		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");
 

Modified: trunk/gobject/valaccodemethodcallmodule.vala
==============================================================================
--- trunk/gobject/valaccodemethodcallmodule.vala	(original)
+++ trunk/gobject/valaccodemethodcallmodule.vala	Tue Dec 16 08:27:59 2008
@@ -461,34 +461,6 @@
 			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;
 		}
 	}
 }

Modified: trunk/vapi/glib-2.0.vapi
==============================================================================
--- trunk/vapi/glib-2.0.vapi	(original)
+++ trunk/vapi/glib-2.0.vapi	Tue Dec 16 08:27:59 2008
@@ -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 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 @@
 	[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;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]