comparison orange/util/string.d @ 9:99c52d46822a

Serialization works now with D2, deserialization still doesn't work
author Jacob Carlborg <doob@me.com>
date Sat, 24 Jul 2010 18:58:18 +0200
parents 11a31bd929f9
children
comparison
equal deleted inserted replaced
8:613a0bb20207 9:99c52d46822a
277 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second"); 277 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second");
278 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string"); 278 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string");
279 } 279 }
280 body 280 body
281 { 281 {
282 return str[beginIndex .. endIndex].dup; 282 version (Tango) return str[beginIndex .. endIndex].dup;
283 else return str[beginIndex .. endIndex].idup;
283 } 284 }
284 285
285 /** 286 /**
286 * Returns a new string that is a substring of the specified string. The substring begins 287 * Returns a new string that is a substring of the specified string. The substring begins
287 * at the specified $(D_PARAM beginIndex) and extends to the character at index 288 * at the specified $(D_PARAM beginIndex) and extends to the character at index
313 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second"); 314 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second");
314 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string"); 315 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string");
315 } 316 }
316 body 317 body
317 { 318 {
318 return str[beginIndex .. endIndex].dup; 319 version (Tango) return str[beginIndex .. endIndex].dup;
320 else return str[beginIndex .. endIndex].idup;
319 } 321 }
320 322
321 /** 323 /**
322 * Returns a new string that is a substring of the specified string. The substring begins 324 * Returns a new string that is a substring of the specified string. The substring begins
323 * at the specified $(D_PARAM beginIndex) and extends to the character at index 325 * at the specified $(D_PARAM beginIndex) and extends to the character at index
349 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second"); 351 assert(beginIndex < endIndex, "mambo.string.substring: The first index was greater the second");
350 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string"); 352 assert(endIndex <= str.length, "mambo.string.substring: The second index was greater then the length of the string");
351 } 353 }
352 body 354 body
353 { 355 {
354 return str[beginIndex .. endIndex].dup; 356 version (Tango) return str[beginIndex .. endIndex].dup;
357 else return str[beginIndex .. endIndex].idup;
355 } 358 }
356 359
357 /** 360 /**
358 * Returns a new string that is a substring of the specified string. The substring begins 361 * Returns a new string that is a substring of the specified string. The substring begins
359 * with the character at the specified index and extends to the end of the string. 362 * with the character at the specified index and extends to the end of the string.
490 493
491 if (end > str.length) 494 if (end > str.length)
492 end = str.length; 495 end = str.length;
493 } 496 }
494 497
495 return str[pos .. end].dup; 498 version (Tango) return str[pos .. end].dup;
499 else return str[pos .. end].idup;
496 } 500 }
497 501
498 /** 502 /**
499 * Returns a new string that is a substring of the given string. 503 * Returns a new string that is a substring of the given string.
500 * 504 *
535 539
536 if (end > str.length) 540 if (end > str.length)
537 end = str.length; 541 end = str.length;
538 } 542 }
539 543
540 return str[pos .. end].dup; 544 version (Tango) return str[pos .. end].dup;
545 else return str[pos .. end].idup;
541 } 546 }
542 547
543 /** 548 /**
544 * Returns a new string that is a substring of the given string. 549 * Returns a new string that is a substring of the given string.
545 * 550 *
580 585
581 if (end > str.length) 586 if (end > str.length)
582 end = str.length; 587 end = str.length;
583 } 588 }
584 589
585 return str[pos .. end].dup; 590 version (Tango) return str[pos .. end].dup;
591 else return str[pos .. end].idup;
586 } 592 }
587 593
588 /** 594 /**
589 * Finds the first occurence of sub in str 595 * Finds the first occurence of sub in str
590 * 596 *
593 * sub = the substring to find 599 * sub = the substring to find
594 * start = where to start finding 600 * start = where to start finding
595 * 601 *
596 * Returns: the index of the substring or size_t.max when nothing was found 602 * Returns: the index of the substring or size_t.max when nothing was found
597 */ 603 */
598 size_t find (string str, string sub, size_t start = 0) 604 size_t find (string str, string sub)
599 { 605 {
600 version (Tango) 606 version (Tango)
601 { 607 {
602 size_t index = str.locatePattern(sub, start); 608 size_t index = str.locatePattern(sub);
603 609
604 if (index == str.length) 610 if (index == str.length)
605 return size_t.max; 611 return size_t.max;
606 612
607 return index; 613 return index;
608 } 614 }
609 615
610 else 616 else
611 return std.string.find(str, sub, start); 617 return std.string.indexOf(str, sub);
618
612 } 619 }
613 620
614 /** 621 /**
615 * Finds the first occurence of sub in str 622 * Finds the first occurence of sub in str
616 * 623 *
619 * sub = the substring to find 626 * sub = the substring to find
620 * start = where to start finding 627 * start = where to start finding
621 * 628 *
622 * Returns: the index of the substring or size_t.max when nothing was found 629 * Returns: the index of the substring or size_t.max when nothing was found
623 */ 630 */
624 size_t find (wstring str, wstring sub, size_t start = 0) 631 size_t find (wstring str, wstring sub)
625 { 632 {
626 version (Tango) 633 version (Tango)
627 { 634 {
628 size_t index = str.locatePattern(sub, start); 635 size_t index = str.locatePattern(sub);
629 636
630 if (index == str.length) 637 if (index == str.length)
631 return size_t.max; 638 return size_t.max;
632 639
633 return index; 640 return index;
634 } 641 }
635 642
636 else 643 else
637 return std.string.find(str, sub, start); 644 return std.string.indexOf(str, sub);
638 } 645 }
639 646
640 /** 647 /**
641 * Finds the first occurence of sub in str 648 * Finds the first occurence of sub in str
642 * 649 *
645 * sub = the substring to find 652 * sub = the substring to find
646 * start = where to start finding 653 * start = where to start finding
647 * 654 *
648 * Returns: the index of the substring or size_t.max when nothing was found 655 * Returns: the index of the substring or size_t.max when nothing was found
649 */ 656 */
650 size_t find (dstring str, dstring sub, size_t start = 0) 657 size_t find (dstring str, dstring sub)
651 { 658 {
652 version (Tango) 659 version (Tango)
653 { 660 {
654 size_t index = str.locatePattern(sub, start); 661 size_t index = str.locatePattern(sub);
655 662
656 if (index == str.length) 663 if (index == str.length)
657 return size_t.max; 664 return size_t.max;
658 665
659 return index; 666 return index;
660 } 667 }
661 668
662 else 669 else
663 return std.string.find(str, sub, start); 670 return std.string.indexOf(str, sub);
664 } 671 }
665 672
666 /** 673 /**
667 * Compares to strings, ignoring case differences. Returns 0 if the content 674 * Compares to strings, ignoring case differences. Returns 0 if the content
668 * matches, less than zero if a is "less" than b, or greater than zero 675 * matches, less than zero if a is "less" than b, or greater than zero
811 * 818 *
812 * Returns: the a C-style 0 terminated string. 819 * Returns: the a C-style 0 terminated string.
813 */ 820 */
814 dchar* toString32z (dstring str) 821 dchar* toString32z (dstring str)
815 { 822 {
816 return (str ~ '\0').ptr; 823 return (str ~ '\0').dup.ptr;
817 } 824 }
818 825
819 /** 826 /**
820 * Converts a C-style 0 terminated string to a wstring 827 * Converts a C-style 0 terminated string to a wstring
821 * 828 *
824 * 831 *
825 * Returns: the converted wstring 832 * Returns: the converted wstring
826 */ 833 */
827 wstring fromString16z (wchar* str) 834 wstring fromString16z (wchar* str)
828 { 835 {
829 return str[0 .. strlen(str)]; 836 return str[0 .. strlen(str)].idup;
830 } 837 }
831 838
832 /** 839 /**
833 * Converts a C-style 0 terminated string to a dstring 840 * Converts a C-style 0 terminated string to a dstring
834 * Params: 841 * Params:
836 * 843 *
837 * Returns: the converted dstring 844 * Returns: the converted dstring
838 */ 845 */
839 dstring fromString32z (dchar* str) 846 dstring fromString32z (dchar* str)
840 { 847 {
841 return str[0 .. strlen(str)]; 848 return str[0 .. strlen(str)].idup;
842 } 849 }
843 850
844 /** 851 /**
845 * Gets the length of the given C-style 0 terminated string 852 * Gets the length of the given C-style 0 terminated string
846 * 853 *