Raymond Toy pushed to branch issue-323-cl-string-casing at cmucl / cmucl

Commits:

3 changed files:

Changes:

  • src/code/string.lisp
    ... ... @@ -676,6 +676,49 @@
    676 676
     	  (setf (schar newstring new-index) (schar string index)))
    
    677 677
     	newstring))))
    
    678 678
     
    
    679
    +#+nil
    
    680
    +(defun string-capitalize (string &key (start 0) end)
    
    681
    +  _N"Given a string, returns a copy of the string with the first
    
    682
    +  character of each ``word'' converted to upper-case, and remaining
    
    683
    +  chars in the word converted to lower case. A ``word'' is defined
    
    684
    +  to be a string of case-modifiable characters delimited by
    
    685
    +  non-case-modifiable chars."
    
    686
    +  (declare (fixnum start))
    
    687
    +  (let* ((string (if (stringp string) string (string string)))
    
    688
    +	 (slen (length string)))
    
    689
    +    (declare (fixnum slen))
    
    690
    +    (with-one-string string start end offset
    
    691
    +      (let ((offset-slen (+ slen offset))
    
    692
    +	    (newstring (make-string slen)))
    
    693
    +	(declare (fixnum offset-slen))
    
    694
    +	(do ((index offset (1+ index))
    
    695
    +	     (new-index 0 (1+ new-index)))
    
    696
    +	    ((= index start))
    
    697
    +	  (declare (fixnum index new-index))
    
    698
    +	  (setf (schar newstring new-index) (schar string index)))
    
    699
    +	(do ((index start (1+ index))
    
    700
    +	     (new-index (- start offset) (1+ new-index))
    
    701
    +	     (newword t)
    
    702
    +	     (char ()))
    
    703
    +	    ((= index (the fixnum end)))
    
    704
    +	  (declare (fixnum index new-index))
    
    705
    +	  (setq char (schar string index))
    
    706
    +	  (cond ((not (alphanumericp char))
    
    707
    +		 (setq newword t))
    
    708
    +		(newword
    
    709
    +		 ;;char is first case-modifiable after non-case-modifiable
    
    710
    +		 (setq char (char-upcase char))
    
    711
    +		 (setq newword ()))
    
    712
    +		;;char is case-modifiable, but not first
    
    713
    +		(t (setq char (char-downcase char))))
    
    714
    +	  (setf (schar newstring new-index) char))
    
    715
    +	(do ((index end (1+ index))
    
    716
    +	     (new-index (- (the fixnum end) offset) (1+ new-index)))
    
    717
    +	    ((= index offset-slen))
    
    718
    +	  (declare (fixnum index new-index))
    
    719
    +	  (setf (schar newstring new-index) (schar string index)))
    
    720
    +	newstring))))
    
    721
    +
    
    679 722
     (defun string-capitalize (string &key (start 0) end)
    
    680 723
       _N"Given a string, returns a copy of the string with the first
    
    681 724
       character of each ``word'' converted to upper-case, and remaining
    
    ... ... @@ -719,7 +762,7 @@
    719 762
     	newstring))))
    
    720 763
     
    
    721 764
     (defun nstring-upcase (string &key (start 0) end)
    
    722
    -  "Given a string, returns that string with all lower case alphabetic
    
    765
    +  _N"Given a string, returns that string with all lower case alphabetic
    
    723 766
       characters converted to uppercase."
    
    724 767
       (declare (fixnum start))
    
    725 768
       (let ((save-header string))
    
    ... ... @@ -732,7 +775,7 @@
    732 775
         save-header)))
    
    733 776
     
    
    734 777
     (defun nstring-downcase (string &key (start 0) end)
    
    735
    -  "Given a string, returns that string with all upper case alphabetic
    
    778
    +  _N"Given a string, returns that string with all upper case alphabetic
    
    736 779
       characters converted to lowercase."
    
    737 780
       (declare (fixnum start))
    
    738 781
       (let ((save-header string))
    
    ... ... @@ -744,6 +787,7 @@
    744 787
                   (char-downcase (schar string index)))))
    
    745 788
         save-header))
    
    746 789
     
    
    790
    +#+nil
    
    747 791
     (defun nstring-capitalize (string &key (start 0) end)
    
    748 792
       "Given a string, returns that string with the first
    
    749 793
       character of each ``word'' converted to upper-case, and remaining
    
    ... ... @@ -769,6 +813,31 @@
    769 813
     	       (setf (schar string index) (char-downcase char))))))
    
    770 814
         save-header))
    
    771 815
     
    
    816
    +(defun nstring-capitalize (string &key (start 0) end)
    
    817
    +  _N"Given a string, returns that string with the first
    
    818
    +  character of each ``word'' converted to upper-case, and remaining
    
    819
    +  chars in the word converted to lower case. A ``word'' is defined
    
    820
    +  to be a string of case-modifiable characters delimited by
    
    821
    +  non-case-modifiable chars."
    
    822
    +  (declare (fixnum start))
    
    823
    +  (let ((save-header string))
    
    824
    +    (with-one-string string start end offset
    
    825
    +      (do ((index start (1+ index))
    
    826
    +	   (newword t)
    
    827
    +	   (char ()))
    
    828
    +	  ((= index (the fixnum end)))
    
    829
    +	(declare (fixnum index))
    
    830
    +	(setq char (schar string index))
    
    831
    +	(cond ((not (alphanumericp char))
    
    832
    +	       (setq newword t))
    
    833
    +	      (newword
    
    834
    +	       ;;char is first case-modifiable after non-case-modifiable
    
    835
    +	       (setf (schar string index) (char-upcase char))
    
    836
    +	       (setq newword ()))
    
    837
    +	      (t
    
    838
    +	       (setf (schar string index) (char-downcase char))))))
    
    839
    +    save-header))
    
    840
    +
    
    772 841
     
    
    773 842
     #+unicode
    
    774 843
     (progn
    

  • src/code/unicode.lisp
    ... ... @@ -641,7 +641,7 @@
    641 641
       (if unicode-word-break
    
    642 642
           (string-capitalize-unicode string :start start :end end :casing casing)
    
    643 643
           (if (eq casing :simple)
    
    644
    -	  (cl:string-capitalize-simple string :start start :end end)
    
    644
    +	  (string-capitalize-simple string :start start :end end)
    
    645 645
     	  (string-capitalize-full string :start start :end end :casing casing))))
    
    646 646
     
    
    647 647
     
    

  • src/general-info/release-21f.md
    ... ... @@ -77,6 +77,9 @@ public domain.
    77 77
         * ~~#298~~ Add `with-float-rounding-mode` macro
    
    78 78
         * ~~#299~~ Enable xoroshiro assembly routine
    
    79 79
         * ~~#314~~ tanh incorrect for large args
    
    80
    +    * ~~#316~~ Support roundtrip character casing
    
    81
    +    * ~~#320~~ Motif variant not defaulted for `x86_linux_clang` config
    
    82
    +    * ~~#321~~ Rename Motif Config.x86 to Config.linux
    
    80 83
       * Other changes:
    
    81 84
       * Improvements to the PCL implementation of CLOS:
    
    82 85
       * Changes to building procedure: