Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Title Case Added to TextFX

jber101
2013-08-13
2013-08-15
  • jber101
    jber101
    2013-08-13

    Before you blast me saying that this is already addressed with Proper Case, let me clarify. What I want is something that will act like Proper Case on all words except for a customizable list of exception words. The list needs to be customizable because different authors have different preferences. However, the default list would be articles (a, an, the), coordinating conjunctions (and, but, for, nor, or, so, yet), and prepositions of 4 or less words (amid, as, at, by, down, from, in, into, near, of, off, on, onto, over, past, per, than, to, up, upon, via, with).

    Does anyone have any recommendations on how to implement this?

    Thanks!

     
  • DV
    DV
    2013-08-14

    via PythonScript.

     
  • jber101
    jber101
    2013-08-14

    Great! Now, if only I knew Python or was a real programmer instead of a researcher posing as one. Little help? :)

     
  • DV
    DV
    2013-08-14

    I'm not an expert of Python, but I'm learning :)
    Something was found in Plugins -> Python Script -> Context-Help, something was found by searching web for "python iterate words in string" and so on.
    You can use the following draft script as the beginning:

    #Uppercase.py
    WordsNoChangeCase = [ "and", 
                          "but", 
                          "for",
                          "nor",
                          "or",
                          "so",
                          "yet" ]
    
    def makeUpperWord(word):
      if word in WordsNoChangeCase:
        return word
      else:
        return word.upper()
    
    s = editor.getSelText()
    words = s.split(" ")
    words[:] = [makeUpperWord(word) for word in words]
    s = " ".join(words)
    editor.replaceSel(s)
    
     
  • DV
    DV
    2013-08-15

    More Python-style version:

    #Uppercase.py
    
    import re
    
    WordsNoChangeCase = [ "and", 
                          "but", 
                          "for",
                          "nor",
                          "or",
                          "so",
                          "yet" ]
    
    def makeUpperWord(word):
      if word in WordsNoChangeCase:
        return word
      else:
        return word.upper()
    
    def processString(f, s):
        result = []
        for m in re.finditer(r"\s+|[^\s]+", s):
            w = m.group()
            result.append(w if w.isspace() else f(w))
        return "".join(result)
    
    s = editor.getSelText()
    editor.replaceSel(processString(makeUpperWord, s))