public Interface map_type;
public TypeSymbol dbus_object_type;
- public Method substring_method;
-
public bool in_plugin = false;
public string module_init_param_name;
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");
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;
}
}
* 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>
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")]
[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;