Changeset 1c28ff5 in OpenModelica for OMCompiler/Compiler/Util/StringUtil.mo


Ignore:
Timestamp:
2021-04-06T15:14:58+02:00 (3 years ago)
Author:
Martin Sjölund <martin@…>
Parents:
f33851b5
git-author:
Martin Sjölund <martin@…> (03/16/21 08:57:25)
git-committer:
Martin Sjölund <martin@…> (04/06/21 15:14:58)
Message:

Handle UTF8 BOM in the diff API

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OMCompiler/Compiler/Util/StringUtil.mo

    r83be5f2b r1c28ff5  
    387387end endsWithNewline;
    388388
     389function convertCharNonAsciiToHex "Converts a single character string to a hex representation if it is not valid unicode"
     390  input output String s;
     391protected
     392  Integer i;
     393  constant String hex[:] = array("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F");
     394algorithm
     395  i := stringCharInt(s);
     396  if i < 128 then
     397    return;
     398  end if;
     399  s := "0x" + hex[intDiv(i, 16)+1] + hex[intMod(i, 16)+1];
     400end convertCharNonAsciiToHex;
     401
     402function stripBOM
     403  input output String s;
     404  output String bom = "";
     405algorithm
     406  if stringLength(s) < 3 then
     407    return;
     408  end if;
     409  if stringGet(s,1) == 239 and
     410     stringGet(s,2) == 187 and
     411     stringGet(s,3) == 191 then
     412    s := substring(s, 4, stringLength(s));
     413    bom := substring(s, 1, 3);
     414  end if;
     415end stripBOM;
     416
    389417annotation(__OpenModelica_Interface="util");
    390418end StringUtil;
Note: See TracChangeset for help on using the changeset viewer.