File: bomstrip.cpp

package info (click to toggle)
bomstrip 9-17
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 256 kB
  • sloc: pascal: 41; ansic: 34; cpp: 34; java: 33; python: 31; sh: 24; makefile: 19; perl: 7; php: 6; ruby: 6; haskell: 6; awk: 2; sed: 1
file content (49 lines) | stat: -rwxr-xr-x 735 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* by Peter Pentchev, 2008, public domain. */

#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

const char	* const utf8bom = "\xef\xbb\xbf";

static void	 usage(const char *);
static void	 outendl(const string &);

static void
usage(const char * const prog)
{
	cerr << "usage: " << prog << endl;
	exit(1);
}

static void
outendl(const string &s)
{
	cout << s;
	if (!cin.eof())
		cout << endl;
}

int
main(const int argc, const char * const argv[])
{
	string s;

	if (argc > 1)
		usage(argv[0]);

	/* Empty? */
	if (!getline(cin, s))
		return 0;

	/* First line... */
	if (!s.substr(0, 3).compare(utf8bom))
		s = s.substr(3);
	outendl(s);

	/* ...and the rest. */
	while (getline(cin, s))
		outendl(s);
}