MCPcopy Create free account
hub / github.com/Genivia/ugrep / cpp

Method cpp

src/output.cpp:1994–2049  ·  view source on GitHub ↗

output string in C/C++

Source from the content-addressed store, hash-verified

1992
1993// output string in C/C++
1994void Output::cpp(const char *data, size_t size)
1995{
1996 const char *s = data;
1997 const char *e = data + size;
1998 const char *t = s;
1999
2000 chr('"');
2001
2002 while (s < e)
2003 {
2004 int c = *s;
2005
2006 if ((c & 0x80) == 0)
2007 {
2008 if (c < 0x20 || c == '"' || c == '\\')
2009 {
2010 str(t, s - t);
2011 t = s + 1;
2012
2013 switch (c)
2014 {
2015 case '\b':
2016 c = 'b';
2017 break;
2018
2019 case '\f':
2020 c = 'f';
2021 break;
2022
2023 case '\n':
2024 c = 'n';
2025 break;
2026
2027 case '\r':
2028 c = 'r';
2029 break;
2030
2031 case '\t':
2032 c = 't';
2033 break;
2034 }
2035
2036 chr('\\');
2037
2038 if (c > 0x20)
2039 chr(c);
2040 else
2041 oct(c);
2042 }
2043 }
2044 ++s;
2045 }
2046 str(t, s - t);
2047
2048 chr('"');
2049}
2050
2051// output quoted string in CSV

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected