title: elisp function to change string case from camel to upcase snake case
body: <p>I spent 3 hours trying to figure out to modify a string at point to different cases, e.g. <code>isFailedUpgrade</code> to <code>IS_FAILED_UPGRADE</code>.</p>
  <p>I got to the point where i can get the string at point to a var <code>text</code> but has no idea how to update a string <code>text</code> to the desired case.</p>
  <pre><code>(defun change-case ()
    (interactive)
    (let* ((bounds (if (use-region-p)
                       (cons (region-beginning) (region-end))
                     (bounds-of-thing-at-point 'symbol)))
           (text   (buffer-substring-no-properties (car bounds) (cdr bounds))))
      (when bounds
        (delete-region (car bounds) (cdr bounds))
        (insert (change-case-helper text)))))
  
  # the following code is rubbish 
  (defun change-case-helper (text)
    (let ((output &quot;&quot;))
      (dotimes (i (length text))
        (concat output (char-to-string (aref text i))))
      output))
  </code></pre>
  <p>Since i am on the journey to learn a little emacs function myself, i prefer to write this function myself instead of use an existing magical function.</p>
  <hr />
  <p>ok after another 2 hours, i think i've figured it out:</p>
  <pre><code>(defun change-case ()
    (interactive)
    (let* ((bounds (if (use-region-p)
                       (cons (region-beginning) (region-end))
                     (bounds-of-thing-at-point 'symbol)))
           (text   (buffer-substring-no-properties (car bounds) (cdr bounds))))
      (when bounds
        (delete-region (car bounds) (cdr bounds))
        (insert (change-case-helper text)))))
  
  (defun change-case-helper (text)
    (when (and text (&gt; (length text) 0))
      (let ((first-char (string-to-char (substring text 0 1)))
            (rest-str (substring text 1)))
        (concat (if (upcasep first-char) (string ?_ first-char) (string (upcase first-char)))
                (change-case-helper rest-str))))
    )
  
  (defun upcasep (c) (and (= ?w (char-syntax c)) (= c (upcase c))))
  </code></pre>
  <p>still feel this is pretty awkward, please comment let me know if there is a better way of writing this function.</p>