RosettaCodeData/Task/CSV-to-HTML-translation/OpenEdge-Progress/csv-to-html-translation-1.openedge
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

50 lines
1.5 KiB
Text

FUNCTION csvToHtml RETURNS CHARACTER (
i_lhas_header AS LOGICAL,
i_cinput AS CHARACTER
):
DEFINE VARIABLE coutput AS CHARACTER NO-UNDO.
DEFINE VARIABLE irow AS INTEGER NO-UNDO.
DEFINE VARIABLE icolumn AS INTEGER NO-UNDO.
DEFINE VARIABLE crow AS CHARACTER NO-UNDO.
DEFINE VARIABLE ccell AS CHARACTER NO-UNDO.
coutput = "<html>~n~t<table>".
DO irow = 1 TO NUM-ENTRIES( i_cinput, "~n":U ):
coutput = coutput + "~n~t~t<tr>".
crow = ENTRY( irow, i_cinput, "~n":U ).
DO icolumn = 1 TO NUM-ENTRIES( crow ):
ccell = ENTRY( icolumn, crow ).
coutput = coutput + "~n~t~t~t" + IF i_lhas_header AND irow = 1 THEN "<th>" ELSE "<td>".
coutput = coutput + REPLACE( REPLACE( REPLACE( ccell, "&", "&amp;" ), "<", "&lt;" ), ">", "&gt;" ).
coutput = coutput + IF i_lhas_header AND irow = 1 THEN "</th>" ELSE "</td>".
END.
coutput = coutput + "~n~t~t</tr>".
END.
coutput = coutput + "~n~t</table>~n</html>".
RETURN coutput.
END FUNCTION. /* csvToHtml */
MESSAGE
csvToHtml(
TRUE,
"Character,Speech" + "~n" +
"The multitude,The messiah! Show us the messiah!" + "~n" +
"Brians mother,<angry>Now you listen here! He's not the messiah; he's a very naughty boy! Now go away!</angry>" + "~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!"
)
VIEW-AS ALERT-BOX.