CSV to HTML translation: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (fix markup) |
No edit summary |
||
Line 1,967: | Line 1,967: | ||
Print "</html>" |
Print "</html>" |
||
Sleep</syntaxhighlight> |
Sleep</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
FB has a native Macintosh web browser, so the HTML output, along with extra credit, is shown in the accompanying screenshot. This code produces a complete, launchable application. |
|||
<syntaxhighlight lang=futurebasic> |
|||
output file "CSV2HTML" |
|||
include "Tlbx WebKit.incl" |
|||
_window = 1 |
|||
begin enum output 1 |
|||
_webView |
|||
end enum |
|||
void local fn BuildWindow |
|||
'~'1 |
|||
CGRect r = fn CGRectMake( 0, 0, 600, 220 ) |
|||
window _window, @"Rosetta Code CSV to HTML", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable |
|||
r = fn CGRectMake( 20, 20, 560, 180 ) |
|||
wkwebview _webView, r,, _window |
|||
end fn |
|||
local fn CSV2HTML as CFStringRef |
|||
'~'1 |
|||
NSUInteger i, count |
|||
CFStringRef csvStr = @"Character,Speech\n¬ |
|||
The multitude,The messiah! Show us the messiah!\n¬ |
|||
Brians mother,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!\n¬ |
|||
The multitude,Who are you\n¬ |
|||
Brians mother,I'm his mother; that's who!\n¬ |
|||
The multitude,Behold his mother! Behold his mother!" |
|||
CFArrayRef linesArray = fn StringComponentsSeparatedByString( csvStr, @"\n" ) |
|||
CFMutableStringRef htmlStr = fn MutableStringWithCapacity(0) |
|||
MutableStringAppendString( htmlStr, @"<table style=\"background:#eee;\">\n" ) |
|||
MutableStringAppendString( htmlStr, @"<tr bgcolor=wheat><th>Character</th><th>Speech</th></tr>" ) |
|||
MutableStringAppendString( htmlStr, @"<caption>From Monty Python's \"The Life of Brian\"</caption>\n" ) |
|||
count = len( linesArray ) |
|||
for i = 1 to count - 1 |
|||
CFStringRef tempStr = linesArray[i] |
|||
CFArrayRef tempArr = fn StringComponentsSeparatedByString( tempStr, @"," ) |
|||
MutableStringAppendString( htmlStr, @"<tr>\n" ) |
|||
MutableStringAppendString( htmlStr, fn StringWithFormat( @"<td style=\"width:120px;\"><b>%@</b></td>>\n", tempArr[0] ) ) |
|||
MutableStringAppendString( htmlStr, fn StringWithFormat( @"<td><i>%@</i></td>\n", tempArr[1] ) ) |
|||
MutableStringAppendString( htmlStr, @"</tr>\n" ) |
|||
next |
|||
MutableStringAppendString( htmlStr, @"</table><br></br>" ) |
|||
end fn = fn StringWithString( htmlStr ) |
|||
local fn LoadHTML2WebView |
|||
'~'1 |
|||
CFStringRef htmlStr = fn CSV2HTML |
|||
fn WKWebViewLoadHTMLString( _webView, htmlStr, NULL ) |
|||
end fn |
|||
void local fn DoDialog( ev as long, tag as long, wnd as long, obj as CFTypeRef ) |
|||
'~'1 |
|||
select (ev) |
|||
case _windowWillClose : end |
|||
end select |
|||
end fn |
|||
on dialog fn DoDialog |
|||
fn BuildWindow |
|||
fn LoadHTML2WebView |
|||
HandleEvents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
[[File:CSV to HTML.png]] |
|||