2019-09-21 14:04:05 +02:00
|
|
|
//
|
|
|
|
// main.cpp
|
|
|
|
// valid-utf8
|
|
|
|
//
|
|
|
|
// Created by Bob Polis at 2019-09-21
|
|
|
|
// Copyright (c) 2019 SwiftCoder. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2020-04-12 22:33:47 +02:00
|
|
|
// libcommon
|
|
|
|
#include <libscstring.hpp>
|
|
|
|
|
2019-09-21 14:04:05 +02:00
|
|
|
// UNIX
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <libgen.h>
|
|
|
|
|
|
|
|
// C++
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int main(int argc, const char * argv[]) {
|
|
|
|
int result = EXIT_SUCCESS;
|
|
|
|
try {
|
|
|
|
string text;
|
|
|
|
if (argc == 1) {
|
|
|
|
cin >> text;
|
|
|
|
} else {
|
2020-04-12 22:33:47 +02:00
|
|
|
text = sc::file_get_contents(argv[1]);
|
2019-09-21 14:04:05 +02:00
|
|
|
}
|
2020-04-12 22:33:47 +02:00
|
|
|
result = sc::is_valid_utf8(text) ? EXIT_SUCCESS : EXIT_FAILURE;
|
2019-09-21 14:04:05 +02:00
|
|
|
} catch (const exception& ex) {
|
|
|
|
cerr << basename(const_cast<char*>(argv[0])) << ": " << ex.what() << '\n';
|
|
|
|
result = EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|