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