OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Usually Proper Title-Case for American English

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
tburcham2
General User
General User


Joined: 17 Mar 2005
Posts: 8

PostPosted: Tue Apr 12, 2005 11:15 am    Post subject: Usually Proper Title-Case for American English Reply with quote


Usually-Proper Title-Case for American English.


This applies a few simple rules for capitalizing titles for
books, music and so on. It capitalizes the first and last
words and every other word not in the list of exceptions.
The exceptions made may or may not be grammatically correct.
This uses a fairly simple approach, which is often right and
usually far better than indiscriminate capitalization. It's
better to get perfect results most of the time than imperfect
results most of the time.
It recognizes many acronyms, and changes them to ALL-CAPS.
You can easily expand the number of recognized acronyms.

It handles the foreign characters in extended ASCII (such as:
, , , , , , and so on)

It's unlikely any code can ever guarantee perfect results
every time, because it would have to understand the English
language about as well as a person for some titles.

This is not well suited for use with personal nor proper
names. That will probably be done with a separate function.

This code is public domain by TheirCorp


Added: April 5, 2006
Bug fixed:
"as" was omitted from the function's list of "exception" words, because it
relied on the word list used by an (open source) spellchecker, which also
omitted the word. So, a title such as: "It's Easy as ABC" would result in
"It's Easy AS ABC"


Added: April 13, 2005
The original subject title "Nearly Proper Title-Case for American English" was a bad
choice. The results have been perfect for most of the titles it was tested on
(over 3000).



Updated April 12, 2005:
Added test for two and three letter words. Any two and three letter words that aren't
listed are assumed to be acronyms. This is about all the string-literal data that StarBasic
can handle in a single module without crashing. This code should be stable as it is.
I've crashed OOO 1.9.87(beta version) many times before getting this code rearranged
so that it won't.
It's due to a known bug (or limitation) which is planned to fixed for a future release
(issue number 45570). This bug can be worked around by using additional modules, or
perhaps loading the data from files.
Code:

Rem  *****  BASIC  *****

'(Usually) Proper Title-case for the English Language

'Replaces selected text in Writer with the (usually)
'proper title-case version of it. This goes beyond merely
'capitalizing the first character of each word. It leaves
'less important words such as "from" and "did" in lower-case.

'It recognizes many acronyms, and changes them to ALL-CAPS.
'You can easily expand the number of recognized acronyms.

'It handles the foreign characters in extended ASCII (such as:
', , , , , , and so on)

'Public domain by TheirWare Corporation 2005
'http://home.midsouth.rr.com/theirware/

Option Explicit

Const Alpha = "abcdefghijklmnopqrstuvwxyz" & ""
Const Num = "0123456789"
Const Delim = " `~!@#$%^&*()-_=+[]\{}|;:"",./<>?"
Const Roman = ",i,ii,iii,iv,v,vi,vii,viii,ix,xi,xii,xiii,xiv,xv,xvi,xvii,xviii,xix,xx,"

Sub Main
Dim oDoc    As Object
Dim oText   As Object
Dim oCursor As Object
Dim oSel    As Object
Dim s       As String
Dim t       As String
Dim n       As Long

    '=====================================
    'get access to the document
    oDoc = ThisComponent
    oText = oDoc.GetText()
    oCursor = oText.createTextCursor()

    '=====================================
    'get selected text
    oSel = oDoc.getCurrentSelection()
    s = oSel.getByIndex(n).getString()

    '=====================================
    'title-case it
    s = TitleCase$(s)

    '=====================================
    'replace selected text with capitalized text
    oSel.getByIndex(n).setString(s)

End Sub



'If u is non-zero then it upper-cases the
'input string, otherwise, it lower-cases it.
Function CaseIt$(Main$, u As Long)
Dim a     As Long
Dim o     As Long
Dim n     As Long
Dim c     As String
Dim t     As String

    t = Main$
    If u <> 0 Then
        u = &H0DF
    Else
        u = &H0FF
        o = 32
    End If

    For n = 1 To Len(t)
        c = Mid$(t, n, 1)
        If InStr(Alpha, c) Then
            Mid$(t, n, 1, Chr$(Asc(c) And u Or o))
        End If
    Next n

    CaseIt$ = t

End Function 'CaseIt$



Function Replace$(Main$, Rep$, New$)
Dim n   As Long
Dim c   As String
    For n = 1 To Len(Main$)
        If Mid(Main$, n, 1) = Rep$ Then Mid(Main$, n, 1, New$)
    Next n
    Replace$ = Main$
End Function


Function Verify(Start As Long, Main$, Ok$) As Long
Dim r   As Long
Dim v   As Long
Dim c   As String

    For v = Start To Len(Main$)
        c = Mid$(Main$, v, 1)
        If InStr(1, Ok$, c, 1) = 0 Then Exit For
    Next v

    If v <= Len(Main$) Then Verify = v

End Function



Function TitleCase$(s As String)
Dim i     As Long
Dim n     As Long
Dim p     As Long
Dim c     As String
Dim t     As String
Dim a()   As String

    s = Replace$(s, "`", "'")       'replace accents with apostrophes
    s = Replace$(s, Chr$(9), " ")   'replace TABs with spaces
    s = Trim$(s)
    If Len(s) = 0 Then Exit Function

    'putting spaces before and after, will make
    'sure all titles start and end with delimiters,
    'and simplify the code.
    s = " " & CaseIt$(s, 0) & " "   'lower-case the entire string

    '----------------------------------
    'take title apart and put the parts into an array
    p = 1
    Do
        '------------------------------
        'get a delimiter from the title
        n = p
        p = Verify(p, s, Delim)
        If p = 0 Then p = Len(s)
        ReDim Preserve a(i)
        a(i) = Mid$(s, n, p - n)
        If p = Len(s) Then Exit Do
        i = i + 1

        '------------------------------
        'get a word from the title
        n = p
        p = Verify(p, s, Alpha & Num)
        ReDim Preserve a(i)
        a(i) = Mid$(s, n, p - n)
        i = i + 1
    Loop


    '----------------------------------
    'capitalize and combine the words and delimiters
    For i = 0 To UBound(a())

        t = t & a(i)
        i = i + 1 : If i > UBound(a()) Then Exit For
        c = Left$(a(i), 1)


        'the exception list (most in alphabetical order)
        n = InStr(",a,all,am,an,and,are,as,at,be,been,both,but,by," & _
        "came,come,coming,could,couldn't,did,didn't,do,does,doesn't," & _
        "don't,down,each,far,few,for,from,go,goes,going,had,has," & _
        "hasn't,have,haven't,he,her,here,hers,herself,him,himself," & _
        "his,if,in,into,is,isn't,it,it's,itself,less,may,me,might," & _
        "mightn't,mine,more,most,my,myself,near,no,nor,not,of,on," & _
        "only,or,ours,out,over,she,should,shouldn't,so,some,that,the," & _
        "theirs,them,there,these,they,this,those,to,under,up,upon," & _
        "us,was,wasn't,we,went,were,what,which,who,will,with,won't," & _
        "would,wouldn't,yet,you,yours,because,than,back,where,other," & _
        "your,away,ain't,get,got,us,'bout,gonna,goin',upper,around," & _
        "about,", "," & a(i) & ",")

        'apply "first and last" rule and exceptions
        If (i = 1) Or (i = UBound(a()) - 1) Or (n = 0) Then
            c = CaseIt$(c, 1)
        End If

        If (n = 0) And Len(a(i)) > 1 Then

            If (Len(a(i)) < 4) And (IsWord(a(i)) = 0) Then
                'if it isn't in the list of 2 and 3-letter words, assume it's an acronym
                n = 1
            ElseIf IsAcronym(a(i)) Then 'scan for it in a list of acronyms
                n = 1
            ElseIf CouldBeWord(a(i)) = 0 Then
                n = 1
            ElseIf InStr(Roman, a(i)) Then 'crude test for roman numbers
                n = 1
            End If

            'put word in ALL-CAPS
            If n Then a(i) = CaseIt$(a(i), 1)

        End If

        '....you can apply some additional rules here.....

        t = t & c & Mid$(a(i), 2)

    Next i

    TitleCase$ = Mid$(t, 2) 'remove the space that was added before

End Function


'These words are broken up into small groups
'so StarBasic can handle them.
'Returns non-zero if "f" is a two or three-letter word
'You can easily add more words
Function IsWord(f As String) As Long
Dim n As Long
Dim t As String

    t = "," & f & ","

    'see if it's a two or three letter word
n = InStr("ad,ah,am,an,at,be,bi,by,co,do,ea,ed,eh,el,em,en,et,ex,fa,ft,go,ha,he,hi,ho," & _
    "hr,id,if,in,it,kg,kl,km,la,lb,lo,ma,me,mg,mi,ml,mm,mo,mt,mu,my,no,nu,ob,of," & _
    "oh,om,on,or,ow,ox,oz,pa,pi,re,so,ti,to,uh,um,up,us,vi,we,wk,wt,xi,xv,xx,ya," & _
    "yd,ye,yo,yr,abs,ace,act,add,adj,ado,adv,adz,aft,age,ago,aha,aid,ail,aim,air," & _
    "ala,alb,ale,all,alp,alt,amp,amt,and,ans,ant,any,ape,apt,arc,are,ark,arm,art,ash,", t)

n = n + InStr("ask,asp,ass,ate,auk,aux,ave,avg,awe,awl,awn,aye,baa,bad,bag,bah,ban,bar,bat,bay," & _
    "bed,bee,beg,bet,bib,bid,big,bin,bit,biz,boa,bob,bod,bog,boo,bop,bot,bow,box,boy," & _
    "bps,bra,bro,brr,bub,bud,bug,bum,bun,bus,but,buy,bye,cab,cad,cal,cam,can,cap,car," & _
    "cat,caw,cay,cob,cod,cog,col,con,coo,cop,cot,cow,cox,coy,cry,cub,cud,cue,cum,cup,", t)

n = n + InStr("cur,cut,dab,dad,dam,day,dew,did,die,dig,dim,din,dip,dis,doc,doe,dog,don,dot,doz," & _
    "dry,dub,dud,due,dug,duh,dun,duo,dye,ear,eat,ebb,eek,eel,egg,ego,eke,elf,elk,elm," & _
    "emu,end,eon,era,ere,erg,err,etc,eve,ewe,eye,fad,fag,fan,far,fat,fax,fay,fed,fee," & _
    "fem,fen,few,fey,fez,fib,fig,fin,fir,fit,fix,flu,fly,foe,fog,fol,fop,for,fox,fro," & _
    "fry,fun,fur,fut,gab,gad,gag,gal,gap,gar,gas,gay,gee,gel,gem,get,gig,gin,git,gnu,", t)

n = n + InStr("gob,god,goo,got,gov,gum,gun,gut,guy,gym,gyp,had,hag,ham,hap,hat,haw,hay,hem,hen," & _
    "hep,hew,hex,hey,hgt,hid,hie,him,hip,hit,hob,hoc,hod,hoe,hog,hon,hop,hos,hot,how," & _
    "hoy,hub,hue,hug,huh,hum,hut,ice,icy,iii,ilk,ill,imp,inf,ink,inn,int,ion,ire,irk," & _
    "ism,ivy,jab,jag,jam,jar,jaw,jay,jet,jib,jig,job,jog,jot,joy,jug,jut,keg,ken,key,", t)

n = n + InStr("kid,kin,kip,kit,lab,lac,lad,lag,lam,lap,las,lat,law,lax,lay,lea,lee,leg,lei,let," & _
    "lex,lib,lid,lie,lip,liq,lit,lob,log,lop,lot,low,lox,lug,lye,mac,mad,mag,man,map," & _
    "mar,mas,mat,maw,max,may,men,mes,met,mew,mid,mil,min,mis,mix,mob,mod,mom,moo,mop," & _
    "mow,mud,mug,mum,mun,mus,mys,nab,nag,nap,nay,neg,net,new,nib,nil,nip,nit,nix,nod," & _
    "non,nor,nos,not,now,nub,nun,nut,ne,oaf,oak,oar,oat,obi,obj,odd,ode,off,oft,ohm,", t)

n = n + InStr("oho,ohs,oil,old,ol,one,ooh,ope,opp,opt,orb,ore,our,out,ova,owe,owl,own,pad,pal," & _
    "pan,pap,par,pas,pat,paw,pay,pea,pee,peg,pen,pep,pet,pew,pie,pig,pin,pip,pit,pix," & _
    "ply,pod,poi,pol,pop,pot,pow,pox,pro,pry,pub,pug,pun,pup,pus,put,pyx,qua,quo,rad," & _
    "rag,rah,raj,ram,ran,rap,rat,raw,ray,red,ref,rep,rev,rib,rid,rig,rim,rip,rob,rod,", t)

n = n + InStr("roe,rot,row,rub,rue,rug,rum,run,rut,rye,sac,sad,sag,sap,sat,saw,sax,say,sci,sea," & _
    "sec,see,set,sew,sex,she,shh,shy,sic,sin,sip,sir,sis,sit,six,ska,ski,sky,sly,sob," & _
    "soc,sod,sol,son,sop,sot,sou,sow,soy,spa,spy,ssh,sty,sub,sud,sue,sum,sun,sup,syn," & _
    "sys,tab,tad,tag,tam,tan,tao,tap,tar,tat,tau,tax,tea,tee,tel,ten,the,tho,thy,tic," & _
    "tie,tin,tip,tit,toe,tog,tom,ton,too,top,tor,tot,tow,toy,try,tty,tub,tug,tum,tun,", t)

n = n + InStr("tut,tux,two,ugh,ult,ump,urn,use,usu,val,van,var,vat,veg,vet,vex,via,vie,vim,vis," & _
    "viz,voe,vol,vow,wad,wag,wan,war,was,wax,way,web,wed,wee,wen,wet,who,why,wig,win," & _
    "wit,woe,wok,won,woo,wop,wot,wow,wry,yak,yam,yap,yaw,yea,yen,yep,yes,yet,yew,yin," & _
    "yip,yon,you,yow,yuk,yum,yup,zag,zap,zed,zig,zip,zit,zoo,", t)

    IsWord = n

End Function 'IsWord


'This tries to determine if a group of letters
'could be a valid word, so acronyms which aren't
'listed can also be put in ALL-CAPS.
Function CouldBeWord(s As String) As Long
Dim n     As Long
Dim t     As String

    t = LCase$(s)
    For n = 1 To Len(t)
       If Instr("0123456789", Mid$(t, n, 1)) Then Exit Function
       If Instr("aeiou", Mid$(t, n, 1)) Then CouldBeWord() = 1 : Exit Function
    Next n

    If InStr(t, "y") Then 'could be a word...
        If Right$(t, 1) = "s" Then t = Left$(t, Len(t) - 1)
        n = InStr(",crwth,crypt,cwm,cyst,hymn,myrrh,myth,nth,rhythm,sylph,syzygy,", "," & t & ",")
        If n Then CouldBeWord() = 1 : Exit Function
    End If

End Function


'These acronyms are broken up into small groups
'so StarBasic can handle them.

'The ones with question marks in front of them are also
'common words, like "soap", for example. To have them
'recognized, you can make another call with slightly
'changed code.

'You can easily add more acronyms
Function IsAcronym(f As String) As Long
Dim n As Long
Dim t As String

    t = "," & f & ","

    'From an open-source spell checker's word list:
n = InStr(",aclu,acth,afdc,ansi,arco,arpa,awol,byob,cacm,cctv,cern,dbms,eeoc,fdic,fica,fnma,fofl,gigo,goto," & _
    "gpss,hdtv,icbm,imho,inri,mirv,nato,ncaa,nlrb,noaa,nyse,oems,ohsa,opec,osha,otoh,parc,reit,risc," & _
    "rofl,rotc,rsvp,rtfm,sase,sccs,sids,smsa,spca,spss,stol,swak,tefl,tesl,ucla,usaf,uscg,usda,usia," & _
    "usmc,usps,ussr,vlsi,vtol,wats,wwii,ymca,ymha,ymmv,ywca,ywha,afaik,algol,aspca,awacs,darpa,fslic," & _
    "naacp,nimby,norad,rsfsr,seato,tenex,tesol,toefl,bitnet,decnet,imnsho,nasdaq,simula,telnet,ultrix," & _
    "unesco,unicef,arpanet,calcomp,centrex,multics,siggraph,", t)

    'Computer-related acronyms
n = n + InStr(",aarp,aasp,aatp,abap,abend,abios,abist,abrd,abrs,abts,acap,acdi,acias,acis,acms,acpi,acss,actlu," & _
    "actpu,actt,acvc,adccp,adios,adlat,adlc,admacs,admd,adpcm,adsc,adsi,adsl,adsp,adsr,aesa,afdw,afii," & _
    "afirm,afis,aftp,agras,aiff,aiim,aisp,alat,alink,aliweb,alos,amandda,amdd,ampl,amps,ancova,andf," & _
    "anova,ansi,aoce,aparen,apcug,apdu,apic,apipa,apis,apnic,apop,appc,appi,appn,apps,aprp,apse,arag," & _
    "aras,arca,arcnet,arll,arma,arpanet,arpl,arta,artic,artt,asai,asap,as3ap,ascc,ascii,asic,asit,aslm,", t)

n = n + InStr(",asmp,aspi,asps,atapi,atdp,atdt,atps,avvid,bacp,bapi,barts,basm,bcnf,bcpl,bdls,bdos,bdsl,becn,bedo," & _
    "bftp,bhis,bidi,bifet,biff,binac,bios,bisdn,bist,bksp,bler,blmc,blos,bmic,bops,bpdu,bpsk,brgc,bsam," & _
    "bscs,btam,?bubl,cacls,cadd,cade,caen,caex,cals,capd,casl,?cass,cassis,catv,cbcr,cbds,cbema,cbga,cbms," & _
    "ccft,ccie,ccitt,ccna,ccnp,ccsis,ccsd,cctld,cdbt,cddi,cdfs,cdia,cdma,cdmf,cdos,cdpd,cdrl,cdsa,cdsl,", t)

n = n + InStr(",celp,cems,ceop,cern,?cert,cfml,cgms,chrp,chtml,ciac,cics,cidr,cifs,ciocs,circ,cisc,civr,cjli,clar," & _
    "cldc,clec,clid,clnp,clos,cltp,clts,cltv,clui,clut,cmak,cnidr,cmip,cmis,cmms,cmmu,cmos,cmov,cmps,cmts," & _
    "cmvc,cmyk,cnaps,cnidr,cnss,cobol,codasyl,coem,coff,cogo,comdex,comm,commat,?comsat,copics,corba,coren," & _
    "cose,coss,cpan,cpcs,cpfr,cpio,cpld,cprm,cram,cren,crom,crtc,?csar,cscw,csds,csfi,csid,cslip,csma,csms," & _
    "cspdn,csram,cssm,csta,ctcp,ctos,ctpa,ctrco,ctss,cusip,cvga,cvia,cwis,cxml,cymk,dacl,?dactlu,dama,damps,", t)

n = n + InStr(",dapie,dari,darms,dasd,davic,dbcs,dbis,dbms,dbwr,dcaf,dcam,dced,dcml,dcom,ddcmp,ddcs,ddeml,ddns,ddos," & _
    "?decnet,?defrag,delstr,dfdr,dfsms,dgis,dhcp,dhtml,dibol,dicom,dids,diip,dila,dimm,disa,dist,dive,divx," & _
    "dlci,dlpi,dmac,dmacs,dmms,dmos,dmpc,dmpp,dmqs,dmsd,dmsdk,dmss,dmtf,dnic,dnie,dnis,docsis,docsv,doip," & _
    "dolap,domf,dpam,dpma,dpmi,dpms,dpof,dpsk,?dptotp,dqdb,dram,drda,drdw,dsap,dsdd,dsea,dshd,dsis,dslam,", t)

n = n + InStr(",dsma,dsml,dsom,dspt,dsqd,dssa,dssi,dsss,dsssl,dstn,dsvd,dtcp,dtmf,dtss,dtvc,duat,dvmrp,dvof,dwdm,dwmt," & _
    "earom,eata,ebasic,ebct,ebcdic,ebnf,ebpp,ecal,ecat,ecma,ecne,ectl,eddc,edif,edifact,edlc,edms,edos,edpm," & _
    "edram,edsac,edtv,edvac,eemac,eems,eeprom,efigs,efts,egrep,ehci,ehllapi,eide,eisa,elan,elec,elos,emacs," & _
    "embarc,emcc,emsapi,emwac,eniac,enss,eosdis,?epic,epld,eprom,epsf,erll,erma,erom,escd,escm,escon,esdi," & _
    "esdram,esmr,essid,etacs,etann,etom,etpl,eula,euvl,evdo,evga,ewan,exca,exif,famos,fapi,fasic,fccset,", t)

n = n + InStr(",fcpga,fcram,fddi,fdhd,fdma,fdsl,fecn,fefo,fepi,feprom,feram,fesdk,ffdc,ffst,fgrep,fhss,fifo,filo,fips," & _
    "flir,fmri,foip,foirl,foldoc,?forth,fortran,fose,fosi,fpce,fpga,fpla,fqdn,frad,frag,fram,frmr,frpi,ftam," & _
    "ftpd,fttb,fttc,fttn,fwtk,gaap,gapi,gart,gatt,gawd,gccd,gddm,gdlc,gecos,geis,geos,gigo,gils,glis,gmdi," & _
    "gosip,gpib,gpio,gprc,gprs,gpss,gradd,grep,gsnw,gstn,guid,gwes,hacmp,hcss,hdcd,hdcp,hdlc,hdmi,hdml,hdsc,", t)

n = n + InStr(",hdsl,hdss,hdtv,hdvd,heos,hgcp,hids,hifd,hippi,hlco,hllapi,hmmp,hmos,holap,hott,hpcc,hpdj,hpfs,hpgl," & _
    "hpib,hplj,hpom,hppa,hppi,hpsb,hptl,hpux,hris,hrms,hrtf,hssi,html,http,https,hwcp,hwdm,iaec,iana,iaup," & _
    "ibcs,ibip,icann,icap,icas,iccp,ices,iclid,icmp,icomp,icsapi,idapi,idde,iden,idms,idnx,idsl,ieee,iemsi," & _
    "ietf,iesg,ifsm,iges,igfet,igmp,igrp,iiop,iitf,ikmp,ilec,imacs,imap,imax,imdb,imds,imei,impa,impi,impp," & _
    "imsi,imsp,imtc,imtv,imux,infs,innd,inta,intel,iocc,iocs,ioctl,iode,iopl,iosga,ipbf,ipcmos,ipcp,ipcs,ipdc,", t)

n = n + InStr(",ipds,ipfc,ipmi,ipng,ipse,ipsec,iptc,irda,irds,irlap,irled,irql,irtf,isakmp,isam,isapi,isbn,iscsi,isdn," & _
    "iskm,ismf,isoc,ispf,isrc,issn,itil,itsm,itug,iuap,ivds,ivis,jaxm,jdbc,jdsl,jedec,jeida,jepi,jfet,jfif," & _
    "jips,jlip,jmapi,jpeg,jpnf,jsse,jtag,jtapi,kefir,kips,kqml,ksds,ksph,laddr,lall,lanacs,landp,lapb,lapd," & _
    "lapm,laser,lata,lavc,lccm,lcos,lcsd,ldap,ldds,lfap,lgpl,lias,lics,liep,lifo,lilo,limdo,limm,lims,lipo,", t)

n = n + InStr(",lisp,lmbcs,lmds,lmos,locis,lpar,lpdu,lsapi,lsass,lspr,ltps,luis,lvds,madymo,majc,maniac,mapi,mapics,marc," & _
    "?masm,mavdm,mbasic,mbcs,mcad,mcga,mcne,mcps,mcsd,mcse,mddbms,mdic,mdlp,mems,merci,mesi,mffs,mfiop,mflops," & _
    "mfpi,mgcp,mget,mgml,micr,mics,midi,midp,mimd,?mime,?minuet,mips,miram,mlapi,mlid,mlppp,mmcd,mmcx,mmds,mmis," & _
    "mmpm,mmvf,mnos,mohll,molap,mops,mosfet,mospf,motd,mpcs,mpeg,mpls,mpmd,mpoa,mpqp,mptn,mpts,mram,mrcf,mrci," & _
    "mrpl,msacm,msau,msav,msbf,mscdex,msce,mschap,mscs,msde,msdn,msdr,msds,msfr,msgina,msie,msimn,msmq,msql,", t)

n = n + InStr(",msrp,msts,msxml,mtbb,mtbf,mtbj,mtrp,mtso,mtst,mttd,mttf,mttr,?mumps,?muse,?music,mvdm,mvga,mvip,nacd,nacs," & _
    "naka,namps,?nand,naplps,nasa,nasdaq,nasi,nasirc,nasker,?navstar,nbma,ncga,ncic,ncmt,ncos,ncsa,ncsc,ncsi," & _
    "nddk,ndef,ndis,ndmp,ndro,nema,?netbios,?netbeui,?netmon,nhrp,?nicad,nicolas,nids,?nimh,nips,niso,nisp,nist," & _
    "nitc,?nlsfunc,nmos,nntp,nopac,nptn,nren,nrzi,nsap,nsapi,nserc,nssc,nstc,nstl,ntas,ntfs,ntia,ntis,ntras,", t)

n = n + InStr(",ntsa,ntsc,numa,nvod,nvram,ocsp,odapi,odbc,odbms,odif,odma,odsi,ofdm,ofmt,ogsa,ogsi,ohci,oidl,olap,olcp,oled," & _
    "olga,olmc,olsp,oltp,onds,onms,ooad,oodb,oodms,ooos,oopl,ooui,opac,?opus,?oracle,ordvac,orom,?oscar,ospf," & _
    "osql,otdr,pabx,pacs,paih,pais,palc,pals,parc,pascal,pata,patn,pbga,pcacias,pcbc,pceb,pcic,pcma,pcmc,pcmcia," & _
    "pcmim,pcnfs,pdial,pdsn,pdss,perc,perl,pert,pgml,phigs,pics,pict,ping,pipo,?pixel,pjpeg,plcc,plds,plmn,plsql," & _
    "pmmu,pmos,pnni,posix,ppds,ppga,ppml,pppoe,pptp,pqfp,pracsa,pram,prmd,prml,profs,prog,?prolog,prom,prng,", t)

n = n + InStr(",prtsc,psapi,psdn,psds,pserver,psid,psinet,pspdn,psram,psrt,pstn,purl,pwscs,qbic,qdos,qemm,qllc,qpsk,qsam," & _
    "qtvr,racf,radar,radb,radsl,?raid,rais,ralu,ramdac,rarp,rasapi,rbbs,rbcs,rboc,rcpt,rdbms,rdclk,rdif,rdram," & _
    "rdsl,rdsr,rdto,rexx,rfid,riff,rime,ripem,rips,risc,rlogin,rlsd,rlsi,rolap,roscoe,rpprom,rqbe,rsac,rscs,rspx," & _
    "rsts,rsvp,rtam,rtcp,rtdm,rtmp,rtos,rtsp,rtti,?rtty,?sabre,sacd,sacl,sadl,saml,?sane,sapi,sars,sasi,sata,", t)

n = n + InStr(",savdm,sbas,sbcs,scada,sccp,sccs,scil,sclm,?scram,scrs,scsa,scsi,sctp,sdam,sdlc,sdmi,sdmmc,sdms,sdns,sdram," & _
    "sdsl,sdtv,sdxf,secc,sepp,sercos,serps,sfdr,sfql,sgcp,sgml,sgram,shtml,sidf,sidh,sigcat,simd,simm,simtel," & _
    "sipc,sipo,sipp,sirds,sisl,slic,slmr,slsi,slss,smdr,smds,smif,smil,smit,smobc,smpc,smps,smram,smtp,?snap," & _
    "snapi,snmp,snrm,?soap,?socks,?soho,soic,sonar,sonet,sota,spap,sparc,spcl,spcs,spec,spga,spid,spki,spld," & _
    "?spool,?spot,spps,?spread,spss,sqos,sram,srapi,srdram,srgb,srpi,ssad,ssap,sscp,ssec,ssga,ssma,sspi,ssrp,", t)

n = n + InStr(",stax,stda,?stdaux,?stderr,?stdin,?stdio,stdm,?stdout,?stdprn,strudl,stsci,svcd,svga,svtc,swac,swais,?swig," & _
    "?swish,?sync,?tacs,taloss,tapcis,tapi,?tasm,?taxi,tbbs,tbga,tcpa,tdma,tdms,tdsr,teml,tfdd,tfel,tftp,thor," & _
    "?ties,tiff,tiga,?tiger,tiiap,timi,tims,?tina,titofet,tkip,tmds,tnef,?tport,tqfp,tradic,tron,tsapi,tsid,tsop," & _
    "tstn,ttcn,tucows,?tums,tvfs,tvol,?twain,twip,uart,ucbe,uddi,udec,udma,uems,uhci,uims,ulsi,umts,?uncol,unep,", t)

n = n + InStr(",?unicom,unii,?univac,unix,unma,unspsc,upnp,urep,usart,usoc,usrt,ussa,uucp,uuid,uxga,vadd,vadsl,?vast,vbns," & _
    "vcos,vcpi,vddm,vdmad,vdsl,vega,vemm,vemmi,?veronica,vesa,vfat,vhdl,vhsic,?vines,?viper,vlan,vliw,vlsi,vlsips," & _
    "vmos,vnos,vofdm,voip,vpdn,vpds,vpsc,vram,vrml,vroomm,vrrp,vsam,vsat,vsio,vsos,vswr,vtam,vtns,vxml,waas,wabi," & _
    "wais,?waits,?warp,wats,wbem,wddx,wdram,?webdav,?webnfs,weft,?well,?wham,?wifi,?wimp,?wine,?wins,?wise,?wisp,", t)

n = n + InStr(",wlan,wmfsdk,wmrm,wnic,wnim,?worm,wosa,wphd,wpos,wpvm,wram,wsapi,wsdl,wsui,wtls,wwis,wysbygi,wysiwyg,xacml," & _
    "xapia,xbrl,xfdl,xhtml,xios,xliff,xpcom,xprm,xrns,xslt,xsmd,xssi,?yahoo,", t)

    IsAcronym = n

End Function


Last edited by tburcham2 on Wed Apr 05, 2006 7:57 am; edited 8 times in total
Back to top
View user's profile Send private message
9point9
Moderator
Moderator


Joined: 31 Aug 2004
Posts: 3875
Location: UK

PostPosted: Tue Apr 12, 2005 11:55 am    Post subject: Reply with quote

Users would obviously have to manually check that it's what they'd want. I'm geussing that it is American English and so it would have to be labelled as such and localizations could easily be made for other locales.
_________________
Arch Linux
OOo 3.2.0

OOoSVN, change control for OOo documents:
http://sourceforge.net/projects/ooosvn/
Back to top
View user's profile Send private message Visit poster's website
tburcham2
General User
General User


Joined: 17 Mar 2005
Posts: 8

PostPosted: Fri Apr 29, 2005 3:21 pm    Post subject: Bug fix and an improvement Reply with quote

.
Fixed a bug which prevented acronyms at the beginning of a title from being
properly capitalized.
Also added a "CouldBeWord" function to help recognize possible acronyms
which aren't listed in "IsAcronym".
Back to top
View user's profile Send private message
WayneC
Newbie
Newbie


Joined: 26 Jan 2005
Posts: 2

PostPosted: Tue Dec 06, 2005 6:09 am    Post subject: OO 2/0 Reply with quote

Added the macro into a new library in OO2 and it comes up as a series of macro's rather than one in the list when attempting to run the macro

Attempts to run any of the listed macro names gives error of

"A scripting framework error occureed when running the Basic Script library1.module1.CaseIt (or other listed macro run)

Message: wrong number of parameters!

May well be my inexperience in adding the macro into the macro list but am wondering if it is due to a change in the macro being needed to handle OO2
Back to top
View user's profile Send private message
Villeroy
Super User
Super User


Joined: 04 Oct 2004
Posts: 10106
Location: Germany

PostPosted: Tue Dec 06, 2005 8:08 am    Post subject: Reply with quote

It's the one called "Main".
Back to top
View user's profile Send private message
tburcham2
General User
General User


Joined: 17 Mar 2005
Posts: 8

PostPosted: Wed Apr 05, 2006 7:53 am    Post subject: Bug fixed in title-case code Reply with quote


Bug fixed in title-case code :
"as" was omitted from the function's list of "exception" words, because it
relied on the word list used by an (open source) spellchecker, which also
omitted the word. So, a title such as: "It's Easy as ABC" would result in
"It's Easy AS ABC"
Back to top
View user's profile Send private message
jkg011
Newbie
Newbie


Joined: 14 Nov 2010
Posts: 2

PostPosted: Sun Nov 14, 2010 11:31 am    Post subject: alternate exception list Reply with quote

Thanks to tburcham2 for this macro! It's been a real time-saver for me.

After using this macro for a while, I realized it was lowercasing more words than I wanted. Here is an alternate exception list that attempts to lowercase only articles, coordinating conjunctions, and prepositions less than 4 letters long. To use this, replace the exception list in the TitleCase routine with this list.

Best wishes,
Jake

Code:
        n = InStr(",the,a,an," & _
        "for,and,nor,but,or,yet,so," & _
        "as,at,but,by,for,in,of,on,out,per,pro,qua,to,up,via," & _
        "", "," & a(i) & ",")
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group