mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Reformat the world
This commit is contained in:
parent
194cb24547
commit
b2f171ec69
714 changed files with 35149 additions and 35203 deletions
|
@ -1,19 +1,18 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "zeek/zeek-config.h"
|
||||
#include "zeek/ZeekString.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <sstream> // Needed for unit testing
|
||||
|
||||
#include "zeek/Val.h"
|
||||
#include "zeek/ID.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/util.h"
|
||||
#include <sstream> // Needed for unit testing
|
||||
|
||||
#include "zeek/3rdparty/doctest.h"
|
||||
#include "zeek/ID.h"
|
||||
#include "zeek/Reporter.h"
|
||||
#include "zeek/Val.h"
|
||||
#include "zeek/util.h"
|
||||
#include "zeek/zeek-config.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_STR(msg) DBG_LOG(zeek::DBG_STRING, msg)
|
||||
|
@ -23,7 +22,8 @@
|
|||
|
||||
using namespace std::string_literals;
|
||||
|
||||
namespace zeek {
|
||||
namespace zeek
|
||||
{
|
||||
|
||||
constexpr int String::EXPANDED_STRING;
|
||||
constexpr int String::BRO_STRING_LITERAL;
|
||||
|
@ -51,7 +51,7 @@ String::String(const char* str) : String()
|
|||
Set(str);
|
||||
}
|
||||
|
||||
String::String(const std::string &str) : String()
|
||||
String::String(const std::string& str) : String()
|
||||
{
|
||||
Set(str);
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void String::Reset()
|
|||
if ( use_free_to_delete )
|
||||
free(b);
|
||||
else
|
||||
delete [] b;
|
||||
delete[] b;
|
||||
|
||||
b = nullptr;
|
||||
n = 0;
|
||||
|
@ -82,11 +82,11 @@ void String::Reset()
|
|||
use_free_to_delete = false;
|
||||
}
|
||||
|
||||
const String& String::operator=(const String &bs)
|
||||
const String& String::operator=(const String& bs)
|
||||
{
|
||||
Reset();
|
||||
n = bs.n;
|
||||
b = new u_char[n+1];
|
||||
b = new u_char[n + 1];
|
||||
|
||||
memcpy(b, bs.b, n);
|
||||
b[n] = '\0';
|
||||
|
@ -96,12 +96,12 @@ const String& String::operator=(const String &bs)
|
|||
return *this;
|
||||
}
|
||||
|
||||
bool String::operator==(const String &bs) const
|
||||
bool String::operator==(const String& bs) const
|
||||
{
|
||||
return Bstr_eq(this, &bs);
|
||||
}
|
||||
|
||||
bool String::operator<(const String &bs) const
|
||||
bool String::operator<(const String& bs) const
|
||||
{
|
||||
return Bstr_cmp(this, &bs) < 0;
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ void String::Adopt(byte_vec bytes, int len)
|
|||
|
||||
// Check if the string ends with a NUL. If so, mark it as having
|
||||
// a final NUL and adjust the length accordingly.
|
||||
final_NUL = (b[len-1] == '\0');
|
||||
final_NUL = (b[len - 1] == '\0');
|
||||
n = len - final_NUL;
|
||||
}
|
||||
|
||||
|
@ -153,8 +153,8 @@ void String::Set(const char* str)
|
|||
if ( str )
|
||||
{
|
||||
n = strlen(str);
|
||||
b = new u_char[n+1];
|
||||
memcpy(b, str, n+1);
|
||||
b = new u_char[n + 1];
|
||||
memcpy(b, str, n + 1);
|
||||
final_NUL = true;
|
||||
use_free_to_delete = false;
|
||||
}
|
||||
|
@ -165,8 +165,8 @@ void String::Set(const std::string& str)
|
|||
Reset();
|
||||
|
||||
n = str.size();
|
||||
b = new u_char[n+1];
|
||||
memcpy(b, str.c_str(), n+1);
|
||||
b = new u_char[n + 1];
|
||||
memcpy(b, str.c_str(), n + 1);
|
||||
final_NUL = true;
|
||||
use_free_to_delete = false;
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ void String::Set(const String& str)
|
|||
|
||||
const char* String::CheckString() const
|
||||
{
|
||||
void *nulTerm;
|
||||
void* nulTerm;
|
||||
if ( n == 0 )
|
||||
return "";
|
||||
|
||||
|
@ -193,17 +193,17 @@ const char* String::CheckString() const
|
|||
else
|
||||
reporter->Error("string without NUL terminator: \"%s\"", exp_s);
|
||||
|
||||
delete [] exp_s;
|
||||
delete[] exp_s;
|
||||
return "<string-with-NUL>";
|
||||
}
|
||||
|
||||
return (const char*) b;
|
||||
return (const char*)b;
|
||||
}
|
||||
|
||||
char* String::Render(int format, int* len) const
|
||||
{
|
||||
// Maxmimum character expansion is as \xHH, so a factor of 4.
|
||||
char* s = new char[n*4 + 1]; // +1 is for final '\0'
|
||||
char* s = new char[n * 4 + 1]; // +1 is for final '\0'
|
||||
char* sp = s;
|
||||
int tmp_len;
|
||||
|
||||
|
@ -211,21 +211,25 @@ char* String::Render(int format, int* len) const
|
|||
{
|
||||
if ( b[i] == '\\' && (format & ESC_ESC) )
|
||||
{
|
||||
*sp++ = '\\'; *sp++ = '\\';
|
||||
*sp++ = '\\';
|
||||
*sp++ = '\\';
|
||||
}
|
||||
|
||||
else if ( (b[i] == '\'' || b[i] == '"') && (format & ESC_QUOT) )
|
||||
{
|
||||
*sp++ = '\\'; *sp++ = b[i];
|
||||
*sp++ = '\\';
|
||||
*sp++ = b[i];
|
||||
}
|
||||
|
||||
else if ( (b[i] < ' ' || b[i] > 126) && (format & ESC_HEX) )
|
||||
{
|
||||
char hex_fmt[16];
|
||||
|
||||
*sp++ = '\\'; *sp++ = 'x';
|
||||
*sp++ = '\\';
|
||||
*sp++ = 'x';
|
||||
sprintf(hex_fmt, "%02x", b[i]);
|
||||
*sp++ = hex_fmt[0]; *sp++ = hex_fmt[1];
|
||||
*sp++ = hex_fmt[0];
|
||||
*sp++ = hex_fmt[1];
|
||||
}
|
||||
|
||||
else if ( (b[i] < ' ' || b[i] > 126) && (format & ESC_DOT) )
|
||||
|
@ -239,7 +243,7 @@ char* String::Render(int format, int* len) const
|
|||
}
|
||||
}
|
||||
|
||||
*sp++ = '\0'; // NUL-terminate.
|
||||
*sp++ = '\0'; // NUL-terminate.
|
||||
tmp_len = sp - s;
|
||||
|
||||
if ( (format & ESC_SER) )
|
||||
|
@ -248,7 +252,7 @@ char* String::Render(int format, int* len) const
|
|||
snprintf(result, tmp_len + 16, "%u ", tmp_len - 1);
|
||||
tmp_len += strlen(result);
|
||||
memcpy(result + strlen(result), s, sp - s);
|
||||
delete [] s;
|
||||
delete[] s;
|
||||
s = result;
|
||||
}
|
||||
|
||||
|
@ -258,29 +262,29 @@ char* String::Render(int format, int* len) const
|
|||
return s;
|
||||
}
|
||||
|
||||
std::ostream& String::Render(std::ostream &os, int format) const
|
||||
std::ostream& String::Render(std::ostream& os, int format) const
|
||||
{
|
||||
char* tmp = Render(format);
|
||||
os << tmp;
|
||||
delete [] tmp;
|
||||
delete[] tmp;
|
||||
return os;
|
||||
}
|
||||
|
||||
std::istream& String::Read(std::istream &is, int format)
|
||||
std::istream& String::Read(std::istream& is, int format)
|
||||
{
|
||||
if ( (format & String::ESC_SER) )
|
||||
{
|
||||
int len;
|
||||
is >> len; // Get the length of the string
|
||||
is >> len; // Get the length of the string
|
||||
|
||||
char c;
|
||||
is.read(&c, 1); // Eat single whitespace
|
||||
is.read(&c, 1); // Eat single whitespace
|
||||
|
||||
char* buf = new char[len+1];
|
||||
char* buf = new char[len + 1];
|
||||
is.read(buf, len);
|
||||
buf[len] = '\0'; // NUL-terminate just for safety
|
||||
buf[len] = '\0'; // NUL-terminate just for safety
|
||||
|
||||
Adopt((u_char*) buf, len+1);
|
||||
Adopt((u_char*)buf, len + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -369,8 +373,7 @@ VectorVal* String::VecToPolicy(Vec* vec)
|
|||
for ( unsigned int i = 0; i < vec->size(); ++i )
|
||||
{
|
||||
String* string = (*vec)[i];
|
||||
auto val = make_intrusive<StringVal>(string->Len(),
|
||||
(const char*) string->Bytes());
|
||||
auto val = make_intrusive<StringVal>(string->Len(), (const char*)string->Bytes());
|
||||
result->Assign(i, std::move(val));
|
||||
}
|
||||
|
||||
|
@ -411,15 +414,14 @@ char* String::VecToString(const Vec* vec)
|
|||
|
||||
bool StringLenCmp::operator()(String* const& bst1, String* const& bst2)
|
||||
{
|
||||
return _increasing ? (bst1->Len() < bst2->Len()) :
|
||||
(bst1->Len() > bst2->Len());
|
||||
return _increasing ? (bst1->Len() < bst2->Len()) : (bst1->Len() > bst2->Len());
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const String& bs)
|
||||
{
|
||||
char* tmp = bs.Render(String::EXPANDED_STRING);
|
||||
os << tmp;
|
||||
delete [] tmp;
|
||||
delete[] tmp;
|
||||
return os;
|
||||
}
|
||||
|
||||
|
@ -461,7 +463,7 @@ String* concatenate(std::vector<data_chunk_t>& v)
|
|||
for ( i = 0; i < n; ++i )
|
||||
len += v[i].length;
|
||||
|
||||
char* data = new char[len+1];
|
||||
char* data = new char[len + 1];
|
||||
|
||||
char* b = data;
|
||||
for ( i = 0; i < n; ++i )
|
||||
|
@ -472,7 +474,7 @@ String* concatenate(std::vector<data_chunk_t>& v)
|
|||
|
||||
*b = '\0';
|
||||
|
||||
return new String(true, (byte_vec) data, len);
|
||||
return new String(true, (byte_vec)data, len);
|
||||
}
|
||||
|
||||
String* concatenate(String::CVec& v)
|
||||
|
@ -483,7 +485,7 @@ String* concatenate(String::CVec& v)
|
|||
for ( i = 0; i < n; ++i )
|
||||
len += v[i]->Len();
|
||||
|
||||
char* data = new char[len+1];
|
||||
char* data = new char[len + 1];
|
||||
|
||||
char* b = data;
|
||||
for ( i = 0; i < n; ++i )
|
||||
|
@ -493,7 +495,7 @@ String* concatenate(String::CVec& v)
|
|||
}
|
||||
*b = '\0';
|
||||
|
||||
return new String(true, (byte_vec) data, len);
|
||||
return new String(true, (byte_vec)data, len);
|
||||
}
|
||||
|
||||
String* concatenate(String::Vec& v)
|
||||
|
@ -513,7 +515,7 @@ void delete_strings(std::vector<const String*>& v)
|
|||
v.clear();
|
||||
}
|
||||
|
||||
} // namespace zeek
|
||||
} // namespace zeek
|
||||
|
||||
TEST_SUITE_BEGIN("ZeekString");
|
||||
|
||||
|
@ -651,7 +653,7 @@ TEST_CASE("searching/modification")
|
|||
CHECK_EQ(std::string(temp), "[this, is, a, test,]");
|
||||
free(temp);
|
||||
|
||||
for ( auto* entry : *splits )
|
||||
for ( auto* entry : *splits )
|
||||
delete entry;
|
||||
delete splits;
|
||||
}
|
||||
|
@ -661,15 +663,15 @@ TEST_CASE("rendering")
|
|||
zeek::String s1("\\abcd\'\"");
|
||||
auto* r = s1.Render(zeek::String::ESC_ESC);
|
||||
CHECK_EQ(std::string(r), "\\\\abcd\'\"");
|
||||
delete [] r;
|
||||
delete[] r;
|
||||
|
||||
r = s1.Render(zeek::String::ESC_QUOT);
|
||||
CHECK_EQ(std::string(r), "\\abcd\\\'\\\"");
|
||||
delete [] r;
|
||||
delete[] r;
|
||||
|
||||
r = s1.Render(zeek::String::ESC_ESC | zeek::String::ESC_QUOT | zeek::String::ESC_SER);
|
||||
CHECK_EQ(std::string(r), "10 \\\\abcd\\\'\\\"");
|
||||
delete [] r;
|
||||
delete[] r;
|
||||
|
||||
zeek::byte_vec text = new u_char[6];
|
||||
text[0] = 3;
|
||||
|
@ -682,17 +684,17 @@ TEST_CASE("rendering")
|
|||
|
||||
r = s2.Render(zeek::String::ESC_HEX);
|
||||
CHECK_EQ(std::string(r), "\\x03\\x04\\x05\\x06\\\'");
|
||||
delete [] r;
|
||||
delete[] r;
|
||||
|
||||
int test_length = 0;
|
||||
r = s2.Render(zeek::String::ESC_DOT, &test_length);
|
||||
CHECK_EQ(std::string(r), "....\\\'");
|
||||
CHECK_EQ(test_length, 7);
|
||||
delete [] r;
|
||||
delete[] r;
|
||||
|
||||
r = s2.Render(zeek::String::BRO_STRING_LITERAL);
|
||||
CHECK_EQ(std::string(r), "\\x03\\x04\\x05\\x06\\\\\\\'");
|
||||
delete [] r;
|
||||
delete[] r;
|
||||
|
||||
std::ostringstream os1;
|
||||
// This uses ESC_HEX, so it should be the same as the test above
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue