MCPcopy Create free account
hub / github.com/cxasm/notepad-- / convertFileToCode

Method convertFileToCode

src/encodeconvert.cpp:310–417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308
309
310CODE_ID EncodeConvert::convertFileToCode(QString& filePath, CODE_ID srcCode, CODE_ID dstCode)
311{
312
313 if (srcCode == CODE_ID::UNKOWN)
314 {
315 return CODE_ID::UNKOWN;
316 }
317
318 QFile file(filePath);
319
320 if (!file.open(QIODevice::ReadOnly | QIODevice::ExistingOnly))
321 {
322 return CODE_ID::UNKOWN;
323 }
324
325 QByteArray content = file.readAll();
326
327 file.close();
328
329 int skip = 0;
330
331 switch (srcCode)
332 {
333 case UNKOWN:
334 break;
335 case ANSI:
336 break;
337 case UNICODE_LE:
338 skip = 2;
339 break;
340 case UNICODE_BE:
341 skip = 2;
342 break;
343 case UTF8_NOBOM:
344 break;
345 case UTF8_BOM:
346 skip = 3;
347 break;
348 case GBK:
349 break;
350 default:
351 break;
352 }
353
354 if (!file.open(QIODevice::WriteOnly | QIODevice::ExistingOnly | QIODevice::Truncate))
355 {
356 return CODE_ID::UNKOWN;
357 }
358
359
360 QByteArray text2Save;
361
362 if (skip == 2 && content.size() >= 2)
363 {
364 text2Save = QByteArray(content.mid(2));
365 }
366 else if (skip == 3 && content.size() >= 3)
367 {

Callers

nothing calls this directly

Calls 6

closeMethod · 0.80
dataMethod · 0.80
isEmptyMethod · 0.80
writeMethod · 0.80
sizeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected