How to resolve the algorithm CSV to HTML translation step by step in the Icon and Unicon programming language
How to resolve the algorithm CSV to HTML translation step by step in the Icon and Unicon programming language
Table of Contents
Problem Statement
Consider a simplified CSV format where all rows are separated by a newline and all columns are separated by commas. No commas are allowed as field data, but the data may contain other characters and character sequences that would normally be escaped when converted to HTML
Create a function that takes a string representation of the CSV data and returns a text string of an HTML table representing the CSV data. Use the following data as the CSV text to convert, and show your output.
Optionally allow special formatting for the first row of the table as if it is the tables header row
(via preferably; CSS if you must).
Let's start with the solution:Step by Step solution about How to resolve the algorithm CSV to HTML translation step by step in the Icon and Unicon programming language
Source code in the icon programming language
procedure main(arglist)
pchar := &letters ++ &digits ++ '!?;. ' # printable chars
write("<TABLE>")
firstHead := (!arglist == "-heading")
tHead := write
while row := trim(read()) do {
if \firstHead then write(" <THEAD>") else tHead(" <TBODY>")
writes(" <TR><TD>")
while *row > 0 do
row ?:= ( (=",",writes("</TD><TD>")) |
writes( tab(many(pchar)) |
("&#" || ord(move(1))) ), tab(0))
write("</TD></TR>")
if (\firstHead) := &null then write(" </THEAD>\n <TBODY>")
tHead := 1
}
write(" </TBODY>")
write("</TABLE>")
end
<TABLE>
<THEAD>
<TR><TD>Character</TD><TD>Speech</TD></TR>
</THEAD>
<TBODY>
<TR><TD>The multitude</TD><TD>The messiah! Show us the messiah!</TD></TR>
<TR><TD>Brians mother</TD><TD><angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry></TD></TR>
<TR><TD>The multitude</TD><TD>Who are you?</TD></TR>
<TR><TD>Brians mother</TD><TD>I'm his mother; that's who!</TD></TR>
<TR><TD>The multitude</TD><TD>Behold his mother! Behold his mother!</TD></TR>
</TBODY>
</TABLE>
You may also check:How to resolve the algorithm Modular arithmetic step by step in the Raku programming language
You may also check:How to resolve the algorithm Knapsack problem/Unbounded step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Jacobi symbol step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Population count step by step in the Miranda programming language
You may also check:How to resolve the algorithm Primality by Wilson's theorem step by step in the Python programming language