Abbreviations, automatic: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 3,164:
</pre>
 
=={{header|FactorFutureBasic}}==
This assumes a text file named "DaysOfWeek.txt" is in the same folder as the code file.
 
<syntaxhighlight lang="futurebasic">
 
include "NSLog.incl"
include resources "DaysOfWeek.txt"
 
local fn DaysOfWeek as CFArrayRef
CFURLRef url
'~'1
CFStringRef string
CFURLRef url
CFArrayRef weeks = NULL
CFStringRef string
CFArrayRef weeks = NULL
url = fn BundleURLForResource( fn BundleMain, @"DaysOfWeek", @"txt", NULL )
 
string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
url = fn BundleURLForResource( fn BundleMain, @"DaysOfWeek", @"txt", NULL )
if ( string )
string = fn StringWithContentsOfURL( url, NSUTF8StringEncoding, NULL )
weeks = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
if ( string )
end if
weeks = fn StringComponentsSeparatedByCharactersInSet( string, fn CharacterSetNewlineSet )
end if
end fn = weeks
 
local fn MinLengthAbbreviation( week as CFStringRef ) as long
CFArrayRef days
'~'1
CFStringRef day1, day2, abbr
CFArrayRef days
long count, length, minLen, index1, index2
CFStringRef day1, day2, abbr
long count, length, minLen, index1, index2
minLen = 1
 
days = fn StringComponentsSeparatedByString( week, @" " )
minLen = 1
if ( len(week days ) == 7 )
days = fn StringComponentsSeparatedByString( week, @" " )
if ( len( days )count == 7len( days )
for index1 = 0 to count - 1
count = len( days )
day1 = days[index1]
for index1 = 0 to count - 1
length = len( day1 )
day1 = days[index1]
length abbr = lenleft( day1, minLen )
for index2 = 0 to count - 1
abbr = left( day1, minLen )
if ( index2 != index1 )
for index2 = 0 to count - 1
day2 = days[index2]
if ( index2 != index1 )
while ( fn StringHasPrefix( day2, abbr ) )
day2 = days[index2]
minLen++
while ( fn StringHasPrefix( day2, abbr ) )
if ( minLen <= length )
minLen++
abbr = left( day1, minLen )
if ( minLen <= length )
else
abbr = left( day1, minLen )
break
else
end if
break
wend
end if
end if
wend
next
end if
next
end if
next
end if
end fn = minLen
 
void local fn Abbreviations
CFArrayRef weeks
'~'1
CFStringRef week
CFArrayRef weeks
CFStringRef week
weeks = fn DaysOfWeek
 
if ( weeks )
weeks = fn DaysOfWeek
for week in weeks
if ( weeks )
if ( len(week) )
for week in weeks
NSLog(@"%ld\t%@",fn MinLengthAbbreviation( week ),week)
if ( len(week) )
else
NSLog(@"%ld\t%@",fn MinLengthAbbreviation( week ),week)
NSLog(@"NULL")
else
end if
NSLog(@"NULL")
next
end if
end if
next
end if
end fn
 
416

edits