------------------------------------------------------------------------------ -- File: CSV2HTML.adb -- Description: Converts CSV (text with Comma Separated Values) input -- into HTML array output. -- CSV is "the" ASCII format for Lotus 1-2-3 and MS Excel -- Created: 11-Nov-2002 -- Syntax (example) csv2html demo_data.html -- Author: Gautier de Montmollin ------------------------------------------------------------------------------ with Ada.Text_IO, Ada.Strings.Fixed; with CSV; -- replaces CSV_Parser procedure CSV2HTML is function Windows8bit_to_HTML (c : Character) return String is begin case c is when 'à' => return "à"; when 'â' => return "â"; when 'ä' => return "ä"; when 'Ä' => return "Ä"; when 'é' => return "é"; when 'É' => return "É"; when 'è' => return "è"; when 'È' => return "È"; when 'î' => return "î"; when 'ô' => return "ô"; when 'ö' => return "ö"; when 'Ö' => return "Ö"; when 'ß' => return "ß"; when 'û' => return "û"; when 'ü' => return "ü"; when 'Ü' => return "Ü"; when '’' => return "'"; when '´' => return "'"; when ' ' => return " "; when others => return (1 => c); end case; end Windows8bit_to_HTML; function Windows8bit_to_HTML (s : String) return String is begin if s = "" then return ""; else return Windows8bit_to_HTML (s (s'First)) & Windows8bit_to_HTML (s (s'First + 1 .. s'Last)); end if; end Windows8bit_to_HTML; line_count : Natural := 0; special_sport : constant Boolean := False; separator : constant Character := ','; -- ';', ',' or ASCII.HT use Ada.Text_IO, Ada.Strings; begin Put_Line (" "); Put_Line (" "); Put_Line (" "); Put_Line (""); -- while not End_Of_File loop line_count := line_count + 1; declare csv_line : constant String := Get_Line; bds : constant CSV.Fields_Bounds := CSV.Get_Bounds (csv_line, separator); begin for i in bds'Range loop Put (""); end loop; end; Put_Line (""); -- if special_sport then case line_count is when 1 => Put (""); -- Gold when 2 => Put (""); -- Silver when 3 => Put (""); -- Bronze when others => Put (""); end case; else Put (""); end if; -- end loop; Put_Line ("
"); -- Trim blanks on both sides (7-Dec-2003) Put ( Windows8bit_to_HTML ( Ada.Strings.Fixed.Trim (CSV.Extract (csv_line, bds, i), Both) ) ); Put ("
"); end CSV2HTML;