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 stem,arg_suffix=e.sub(/([0-9])?(u?(i|s|b)|h|f|d)v?$/,'-\\0').split('-')
38 if arg_suffix && arg_suffix!=''
39 stems[stem][arg_suffix]||=0
40 stems[stem][arg_suffix]+=1
42 #pp [orig,stem,arg_suffix||'',vendor_suffix]
43 [orig,stem,arg_suffix||'',vendor_suffix]
45 split.collect do |orig,e,arg_suffix,vendor_suffix|
46 shared_stem=stems[e].keys.length > 1
47 e_split=(shared_stem ? e : e+arg_suffix).gsub(/([a-z])([A-Z0-9])/,'\\1-\\2').split('-')
48 [orig,*e_split].concat([shared_stem ? arg_suffix : '',vendor_suffix])