5 # remove prefix if it's there
6 s=s.slice(prefix.length..-1) if prefix and s[0...prefix.length]==prefix
8 # prefix underscore->alpha or uppercase->lowercase with dash
9 s.gsub!(/(_+[a-zA-Z]|[A-Z])(?=[a-z])/) do |m|
12 # split off any numerical groups
14 # split off any two or more-letter acronyms at the end (eg. EXT NV ARB ATI SGIX etc)
15 s.sub!(/[A-Z]{2,}$/,"-\\0")
16 # group together any bouts of -s and _s into a single dash
28 GL_SUFFIXES=Regexp.new('('+["IBM","3DFX","SGIS","SUNX","HP","GREMEDY","APPLE","MESA","SUN","INTEL","NV","ARB","SGIX","EXT","ATI"].join('|')+')$')
34 [e,*e.sub(GL_SUFFIXES,'-\\1').split('-')]
35 end.collect do |orig,e,vendor_suffix|
36 #puts("Expanding e #{e.inspect} to #{e.sub(/([0-9])?(u?(i|s|b)|h|f|d)v?$/,'-\\0')}")
37 stem,arg_suffix=e.sub(/([0-9])?(u?(i|s|b)|h|f|d)v?$/,'-\\0').split('-')
39 if arg_suffix && arg_suffix!=''
40 stems[stem][arg_suffix]||=0
41 stems[stem][arg_suffix]+=1
43 #pp [orig,stem,arg_suffix||'',vendor_suffix]
44 [orig,stem,arg_suffix||'',vendor_suffix]
46 # re-join endings that do not share a stem with another function name
47 split.collect do |orig,e,arg_suffix,vendor_suffix|
48 # also keep those ending in 'v', as these are never (probably) going to be at the end of words
49 # also keep 'i' as these are all integer suffices
50 # other special-case words
51 shared_stem=((stems[e].keys.length > 1) or arg_suffix.match(/v$/) or arg_suffix=='i' \
52 or e.match(/Bounds$/) or e.match(/Depth$/))
53 # special case, things ending in edv (ie. participle-v), reattach 'd' and remove from arg_suffix
54 if (e.match(/e$/) and arg_suffix.match(/^d.*v$/))
56 arg_suffix=arg_suffix[1..-1]
57 puts "Fixing participle-v case: #{orig.inspect}, #{e.inspect} suffix: #{arg_suffix.inspect}"
59 e_split=(shared_stem ? e : e+arg_suffix).gsub(/([a-z])([A-Z0-9])/,'\\1-\\2').split('-')
60 if arg_suffix!='' and not shared_stem
61 puts "Re-attaching arg_suffix for #{orig.inspect}, #{e.inspect}+#{arg_suffix.inspect}"
63 [orig,*e_split].concat([shared_stem ? arg_suffix : '',vendor_suffix])