Well it should be pretty simple, first establish the correct width of each column by iterating over all data lines, and place the separators | accordingly. Then replace the spaces in between by the proper data texts. The === line can then be inserted easily.
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”