CSV to HTML translation: Difference between revisions

Content added Content deleted
mNo edit summary
m (→‎{{header|FutureBasic}}: Inserted code indents)
Line 1,980: Line 1,980:
_window = 1
_window = 1
begin enum output 1
begin enum output 1
_webView
_webView
end enum
end enum


void local fn BuildWindow
void local fn BuildWindow
CGRect r = fn CGRectMake( 0, 0, 600, 220 )
'~'1
window _window, @"Rosetta Code CSV to HTML", r, NSWindowStyleMaskTitled + NSWindowStyleMaskClosable
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
r = fn CGRectMake( 20, 20, 560, 180 )
wkwebview _webView, r,, _window
end fn
end fn


local fn CSV2HTML as CFStringRef
local fn CSV2HTML as CFStringRef
NSUInteger i, count
'~'1
NSUInteger i, count
CFStringRef csvStr = @"Character,Speech\n¬

The multitude,The messiah! Show us the messiah!\n¬
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,Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!\n¬
Brians mother,I'm his mother; that's who!\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!"
The multitude,Behold his mother! Behold his mother!"
CFArrayRef linesArray = fn StringComponentsSeparatedByString( csvStr, @"\n" )

CFMutableStringRef htmlStr = fn MutableStringWithCapacity(0)
CFArrayRef linesArray = fn StringComponentsSeparatedByString( csvStr, @"\n" )
MutableStringAppendString( htmlStr, @"<table style=\"background:#eee;\">\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, @"<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 )
MutableStringAppendString( htmlStr, @"<caption>From Monty Python's \"The Life of Brian\"</caption>\n" )
for i = 1 to count - 1
count = len( linesArray )
CFStringRef tempStr = linesArray[i]
for i = 1 to count - 1
CFArrayRef tempArr = fn StringComponentsSeparatedByString( tempStr, @"," )
CFStringRef tempStr = linesArray[i]
MutableStringAppendString( htmlStr, @"<tr>\n" )
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 style=\"width:120px;\"><b>%@</b></td>>\n", tempArr[0] ) )
MutableStringAppendString( htmlStr, fn StringWithFormat( @"<td><i>%@</i></td>\n", tempArr[1] ) )
MutableStringAppendString( htmlStr, fn StringWithFormat( @"<td><i>%@</i></td>\n", tempArr[1] ) )
MutableStringAppendString( htmlStr, @"</tr>\n" )
next
MutableStringAppendString( htmlStr, @"</tr>\n" )
MutableStringAppendString( htmlStr, @"</table><br></br>" )
next
MutableStringAppendString( htmlStr, @"</table><br></br>" )
end fn = fn StringWithString( htmlStr )
end fn = fn StringWithString( htmlStr )


local fn LoadHTML2WebView
local fn LoadHTML2WebView
CFStringRef htmlStr = fn CSV2HTML
'~'1
fn WKWebViewLoadHTMLString( _webView, htmlStr, NULL )
CFStringRef htmlStr = fn CSV2HTML
fn WKWebViewLoadHTMLString( _webView, htmlStr, NULL )
end fn
end fn


void local fn DoDialog( ev as long, tag as long, wnd as long, obj as CFTypeRef )
void local fn DoDialog( ev as long, tag as long, wnd as long, obj as CFTypeRef )
select (ev)
'~'1
case _windowWillClose : end
select (ev)
end select
case _windowWillClose : end
end select
end fn
end fn


Line 2,042: Line 2,038:
{{output}}
{{output}}
[[File:CSV to HTML.png]]
[[File:CSV to HTML.png]]





=={{header|Go}}==
=={{header|Go}}==