Skip to content

Commit

Permalink
Don't include SliceBuilder.h in Status.h.
Browse files Browse the repository at this point in the history
  • Loading branch information
levlam committed May 20, 2021
1 parent 65c3c89 commit 5e7adcd
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
5 changes: 2 additions & 3 deletions tdutils/td/utils/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#pragma once

#include "td/utils/common.h"
#include "td/utils/format.h"
#include "td/utils/Slice.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Status.h"
Expand Down Expand Up @@ -99,7 +98,7 @@ class ParserImpl {
}
SliceT res = read_till_nofail(c);
if (ptr_ == end_ || ptr_[0] != c) {
status_ = Status::Error(PSLICE() << "Read till " << tag("char", c) << " failed");
status_ = Status::Error(PSLICE() << "Read till '" << c << "' failed");
return SliceT();
}
return res;
Expand All @@ -126,7 +125,7 @@ class ParserImpl {
return;
}
if (ptr_ == end_ || ptr_[0] != c) {
status_ = Status::Error(PSLICE() << "Skip " << tag("char", c) << " failed");
status_ = Status::Error(PSLICE() << "Skip '" << c << "' failed");
return;
}
ptr_++;
Expand Down
30 changes: 30 additions & 0 deletions tdutils/td/utils/Status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
#include "td/utils/Status.h"

#include "td/utils/SliceBuilder.h"

#if TD_PORT_WINDOWS
#include "td/utils/port/wstring_convert.h"
#endif
Expand Down Expand Up @@ -55,4 +57,32 @@ string winerror_to_string(int code) {
}
#endif

Status Status::move_as_error_prefix(Slice prefix) const {
CHECK(is_error());
Info info = get_info();
switch (info.error_type) {
case ErrorType::General:
return Error(code(), PSLICE() << prefix << message());
case ErrorType::Os:
return Status(false, ErrorType::Os, code(), PSLICE() << prefix << message());
default:
UNREACHABLE();
return {};
}
}

Status Status::move_as_error_suffix(Slice suffix) const TD_WARN_UNUSED_RESULT {
CHECK(is_error());
Info info = get_info();
switch (info.error_type) {
case ErrorType::General:
return Error(code(), PSLICE() << message() << suffix);
case ErrorType::Os:
return Status(false, ErrorType::Os, code(), PSLICE() << message() << suffix);
default:
UNREACHABLE();
return {};
}
}

} // namespace td
30 changes: 3 additions & 27 deletions tdutils/td/utils/Status.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "td/utils/logging.h"
#include "td/utils/ScopeGuard.h"
#include "td/utils/Slice.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/StackAllocator.h"
#include "td/utils/StringBuilder.h"

Expand Down Expand Up @@ -325,32 +324,9 @@ class Status {
return status.move_as_error_suffix(message());
}

Status move_as_error_prefix(Slice prefix) const TD_WARN_UNUSED_RESULT {
CHECK(is_error());
Info info = get_info();
switch (info.error_type) {
case ErrorType::General:
return Error(code(), PSLICE() << prefix << message());
case ErrorType::Os:
return Status(false, ErrorType::Os, code(), PSLICE() << prefix << message());
default:
UNREACHABLE();
return {};
}
}
Status move_as_error_suffix(Slice suffix) const TD_WARN_UNUSED_RESULT {
CHECK(is_error());
Info info = get_info();
switch (info.error_type) {
case ErrorType::General:
return Error(code(), PSLICE() << message() << suffix);
case ErrorType::Os:
return Status(false, ErrorType::Os, code(), PSLICE() << message() << suffix);
default:
UNREACHABLE();
return {};
}
}
Status move_as_error_prefix(Slice prefix) const TD_WARN_UNUSED_RESULT;

Status move_as_error_suffix(Slice suffix) const TD_WARN_UNUSED_RESULT;

private:
struct Info {
Expand Down

0 comments on commit 5e7adcd

Please sign in to comment.