Skip to content

Commit

Permalink
string_view by simple value
Browse files Browse the repository at this point in the history
nullptr protection in a function
  • Loading branch information
eteran committed Dec 7, 2017
1 parent cf5c94e commit 83ffc49
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5796,7 +5796,11 @@ void MainWindow::action_Detach_Document_Dialog(DocumentWidget *document) {
* @return
*/
MainWindow *MainWindow::fromDocument(const DocumentWidget *document) {
return qobject_cast<MainWindow *>(document->window());
if(document) {
return qobject_cast<MainWindow *>(document->window());
}

return nullptr;
}

/*
Expand Down
2 changes: 1 addition & 1 deletion source/interpret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ NString AllocNStringCpyEx(const QString &s) {
return string;
}

NString AllocNStringCpyEx(const view::string_view s) {
NString AllocNStringCpyEx(view::string_view s) {
size_t length = s.size();

NString string = AllocNStringEx(length + 1);
Expand Down
4 changes: 2 additions & 2 deletions source/interpret.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void PreemptMacro();

char *AllocStringCpyEx(const std::string &s);
NString AllocNStringCpyEx(const QString &s);
NString AllocNStringCpyEx(const view::string_view s);
NString AllocNStringCpyEx(view::string_view s);
void GarbageCollectStrings();
Symbol *PromoteToGlobal(Symbol *sym);
void FreeProgram(Program *prog);
Expand Down Expand Up @@ -268,7 +268,7 @@ inline DataValue to_value(bool n) {
return DV;
}

inline DataValue to_value(const view::string_view str) {
inline DataValue to_value(view::string_view str) {
DataValue DV;
DV.tag = STRING_TAG;
DV.val.str = AllocNStringCpyEx(str);
Expand Down
2 changes: 1 addition & 1 deletion source/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ static bool searchLine(const std::string &line, const std::string &regex) {
}

// Check if a line has non-ws characters
static bool lineEmpty(const view::string_view line) {
static bool lineEmpty(view::string_view line) {

for(char ch : line) {
if(ch == '\n') {
Expand Down
2 changes: 1 addition & 1 deletion util/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void moveItem(Cont &cont, int from, int to) {
// string_view algorithms

template <class Ch, class Tr>
constexpr view::basic_string_view<Ch, Tr> substr(const view::basic_string_view<Ch, Tr> &str, typename view::basic_string_view<Ch, Tr>::size_type pos, typename view::basic_string_view<Ch, Tr>::size_type count = view::basic_string_view<Ch, Tr>::npos) {
constexpr view::basic_string_view<Ch, Tr> substr(view::basic_string_view<Ch, Tr> str, typename view::basic_string_view<Ch, Tr>::size_type pos, typename view::basic_string_view<Ch, Tr>::size_type count = view::basic_string_view<Ch, Tr>::npos) {
return str.substr(pos, count);
}

Expand Down

0 comments on commit 83ffc49

Please sign in to comment.