Exemple #1
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Reads checklist from file encoded in UTF-8.
///
/// @retval true  data loaded 
/// @retval false data load error
///
static bool LoadUtfChecklist(const TCHAR* fileName) {
  Utf8File file;
  if (!file.Open(fileName, Utf8File::io_read)) {
    StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE);
    return(false);
  }

  #if TESTBENCH
  StartupStore(_T(". Loading notes <%s>%s"),fileName,NEWLINE);
  #endif

  TCHAR TempString[MAXNOTETITLE];
  TCHAR Details[MAXNOTEDETAILS+1];
  TCHAR Name[MAXNOTETITLE+1];
  bool inDetails = false;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;

  while (file.ReadLn(TempString, MAXNOTETITLE)) {
    // skip comment lines
    if (TempString[0] == _T('#'))
      continue;
    
    AddChecklistLine(TempString, Details, Name, inDetails);
  } // while
  
  if (inDetails) {
    _tcscat(Details,TEXT("\r\n"));
    addChecklist(Name, Details);
  }
 
  return(true);
} // LoadUtfChecklist 
Exemple #2
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Reads checklist from file encoded in UTF-8.
///
/// @retval true  data loaded
/// @retval false data load error
///
static bool LoadUtfChecklist(const TCHAR* fileName, bool warn) {
  Utf8File file;
  if (!file.Open(fileName, Utf8File::io_read)) {
    if (warn) StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE);
    return(false);
  }

  #if TESTBENCH
  StartupStore(_T(". Loading UTF notes <%s>%s"),fileName,NEWLINE);
  #endif

  TCHAR TempString[MAXNOTETITLE];
  TCHAR Details[MAXNOTEDETAILS+1];
  TCHAR Name[MAXNOTETITLE+1];
  bool inDetails = false;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;
  bool firstline=true;

  while (file.ReadLn(TempString, MAXNOTETITLE)) {
    // skip comment lines
    if (TempString[0] == _T('#')) {
      firstline=false;
      continue;
    }

    // Skip BOMs, if existing. Just to be sure, we only check the very first line of the file.
    // UTF8 BOM: 0xef 0xbb 0xbf
    // Unicode l.e. BOM: 0xff 0xfe (not supported)
    // Unicode b.e. BOM: 0xfe 0xff (not supported)

    if (firstline && (byte)TempString[0]==0xef && (byte)TempString[1]==0xbb && (byte)TempString[2]==0xbf) {
       #ifdef TESTBENCH
       StartupStore(_T("... LoadUtfChecklist, ignoring UTF8 BOM%s\n"),NEWLINE);
       #endif
       AddChecklistLine(&TempString[3], Details, Name, inDetails);
    } else {
       if (firstline && ((unsigned)TempString[0]==0xffef || (unsigned)TempString[0]==0xfeff)) {
          #ifdef TESTBENCH
          StartupStore(_T("... LoadUtfChecklist, ignoring UNICODE BOM%s\n"),NEWLINE);
          #endif
          AddChecklistLine(&TempString[1], Details, Name, inDetails);
       } else {
          AddChecklistLine(TempString, Details, Name, inDetails);
       }
    }
    firstline=false;
  } // while

  if (inDetails) {
    _tcscat(Details,TEXT(ENDOFLINE));
    addChecklist(Name, Details);
  }

  return(true);
} // LoadUtfChecklist