~ubuntu-branches/ubuntu/oneiric/spl/oneiric

« back to all changes in this revision

Viewing changes to builtins.c

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2007-11-21 19:12:02 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20071121191202-qvdw2cqfh8rwk160
Tags: 1.0~pre4-1ubuntu1
* Merge from Debian unstable (LP: #181166), Ubuntu remaining changes:
  - Change build-depends from
    libcurl3-gnutls-dev to libcurl4-gnutls-dev
* Modify Maintainer value to match Debian-Maintainer-Field Spec

Show diffs side-by-side

added added

removed removed

Lines of Context:
543
543
}
544
544
 
545
545
/**
 
546
 * Returns the section of given string
 
547
 * starting at offset with length number of characters.
 
548
 *
 
549
 * If length is 0 or out of range (offset + length > total length),
 
550
 * then the length is adjusted to include the entire string starting
 
551
 * at given offset.
 
552
 *
 
553
 * TODO: check if this causes memory leaks.
 
554
 */ 
 
555
// builting substring(string,offset,length)
 
556
struct spl_node *spl_builtin_substring(struct spl_task *task, void *data UNUSED)
 
557
{
 
558
        char *text = spl_clib_get_string(task);
 
559
        int offset = spl_clib_get_int(task);
 
560
        int length = spl_clib_get_int(task);
 
561
 
 
562
        struct spl_string *original = spl_string_printf(0,0,0,"%s",text);
 
563
 
 
564
        //printf("substring settings: original text: %s; offset: %d; length: %d\n",original->text,offset,length);
 
565
        
 
566
        if (offset < 0 || length <= 0 || (unsigned int)offset > original->total_len)
 
567
        {
 
568
                //printf("invalid range settings, returning empty string\n");
 
569
                return SPL_NEW_STRING_DUP("");
 
570
        }
 
571
        else
 
572
        {
 
573
                if ((unsigned int)offset + (unsigned int)length > original->total_len)
 
574
                        length = original->total_len - offset;
 
575
                struct spl_string *substr = spl_string_split(original,offset,length);
 
576
                //printf("spl substring: %s\n",substr->text);
 
577
                struct spl_node *result = spl_get(0);
 
578
                spl_set_spl_string(result,substr);
 
579
                //printf("result value: %s\n",result->value_string->text);
 
580
                return result;
 
581
        }
 
582
}
 
583
 
 
584
/**
546
585
 * The setlocale() function is used to set or query the program's current locale.
547
586
 *
548
587
 * This is a simple wrapper for the C setlocale() function. The 'category'
677
716
struct spl_node *spl_builtin_underscore(struct spl_task *task, void *data UNUSED)
678
717
{
679
718
        char *message = spl_clib_get_string(task);
 
719
#ifdef ENABLE_GETTEXT_SUPPORT
680
720
        char *domain = spl_clib_get_string(task);
 
721
#else
 
722
        spl_clib_get_string(task);
 
723
#endif
681
724
        int args_counter = spl_clib_get_argc(task);
682
725
 
683
726
        char *args[args_counter];
694
737
#ifdef ENABLE_GETTEXT_SUPPORT
695
738
        translation = dgettext(domain && *domain ? domain : 0, message);
696
739
#else
697
 
        if (domain) { 0; }
698
740
        translation = message;
699
741
#endif
700
742
 
804
846
 
805
847
        spl_clib_reg(vm, "rand", spl_builtin_rand, 0);
806
848
 
 
849
        spl_clib_reg(vm, "substring", spl_builtin_substring, 0);
 
850
 
807
851
        spl_clib_reg(vm, "setlocale", spl_builtin_setlocale, 0);
808
852
        spl_clib_reg(vm, "bindtextdomain", spl_builtin_bindtextdomain, 0);
809
853
        spl_clib_reg(vm, "textdomain", spl_builtin_textdomain, 0);