{"action":"created","comment":{"url":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/comments/65009864","id":65009864,"diff_hunk":"@@ -0,0 +1,209 @@\n+#include \"my_string.h\"\n+#include <memory>\n+\n+        MyString::MyString()\n+        {\n+            mBuffer=nullptr;\n+        }\n+\n+        MyString::MyString(const char* other)\n+        {\n+            mBuffer = std::make_unique<char[]>(std::strlen(other) + 1);\n+            std::strcpy(mBuffer.get(), other);\n+        }\n+\n+        MyString::MyString(const MyString& other)\n+        {\n+            mBuffer = std::make_unique<char[]>(other.size() + 1);\n+            std::strcpy(mBuffer.get(), other.mBuffer.get());\n+        }\n+\n+        std::size_t MyString::size() const\n+        {\n+            if(!mBuffer)\n+                return 0;\n+\n+            return std::strlen(mBuffer.get());\n+        }\n+\n+        bool MyString::empty() const\n+        {\n+            return mBuffer == nullptr || mBuffer.get()[0] == 0;\n+        }\n+\n+        const char* MyString::c_str() const\n+        {\n+            if(!mBuffer)\n+                return \"\";\n+\n+            return mBuffer.get();\n+        }\n+\n+        char MyString::operator[](std::size_t index) const\n+        {\n+            return mBuffer.get()[index];\n+        }\n+        char& MyString::operator[](std::size_t index)\n+        {\n+            return mBuffer.get()[index];\n+        }\n+\n+        bool MyString::operator==(const MyString& other) const\n+        {\n+            if(this -> empty() && other.empty())\n+                //TODO: this is not completely right just yet. we need nullptr checks for later on.\n+                return true;\n+\n+            return std::strcmp(mBuffer.get(), other.mBuffer.get()) == 0;\n+        }\n+        bool MyString::operator!=(const MyString& other) const\n+        {\n+            return !(*this==other);\n+        }\n+\n+        bool MyString::operator<(const MyString& other) const\n+        {\n+            if(this->empty() && other.empty())\n+                return false;\n+\n+            return std::strcmp(this->c_str(), other.c_str()) < 0;\n+        }\n+\n+        bool MyString::operator<=(const MyString& other) const\n+        {\n+            if(this->empty() && other.empty())\n+                return true;\n+\n+            return std::strcmp(this->c_str(), other.c_str()) <= 0;\n+        }\n+\n+        bool MyString::operator>(const MyString& other) const\n+        {\n+            if(this->empty() && other.empty())\n+                return true;\n+\n+            return std::strcmp(this->c_str(), other.c_str()) > 0;\n+        }\n+\n+        bool MyString::operator>=(const MyString& other) const\n+        {\n+            if(this->empty() && other.empty())\n+                return true;\n+\n+            return std::strcmp(this->c_str(), other.c_str()) >= 0;\n+        }\n+\n+        MyString& MyString::operator=(const MyString& other)\n+        {\n+            if(!other.mBuffer)\n+            {\n+                clearBuffer();\n+            }\n+            else\n+            {\n+                auto newSize = other.size() + 1;\n+                auto newBuffer = std::make_unique<char[]>(newSize);\n+                std::strcpy(newBuffer.get(), other.mBuffer.get());\n+                mBuffer.swap(newBuffer);\n+            }\n+\n+            return *this;\n+        }\n+\n+        MyString& MyString::operator=(const char* other)\n+        {\n+            if(other == nullptr)\n+            {\n+                clearBuffer();\n+            }\n+            else\n+            {\n+                auto newSize =std::strlen(other) + 1;\n+                auto newBuffer = std::make_unique<char[]>(newSize);\n+\n+                std::strcpy(newBuffer.get(), other);\n+                mBuffer.swap(newBuffer);\n+            }\n+\n+            return *this;\n+        }\n+\n+        MyString& MyString::operator+=(const char* other)\n+        {\n+            if(other != nullptr && other[0] != '\\0')\n+            {\n+                auto newSize = this->size() + std::strlen(other) + 1;\n+                auto copyStartIndex = this->size();\n+\n+                auto newBuffer = std::make_unique<char[]>(newSize);\n+                std::strcpy(newBuffer.get(), this->c_str());\n+                std::strcpy(newBuffer.get() + copyStartIndex, other);\n+\n+                mBuffer.swap(newBuffer);\n+            }\n+\n+            return *this;\n+        }\n+\n+        MyString& MyString::operator+=(const MyString& other)\n+        {\n+            if(!other.empty())\n+            {\n+                auto newSize = this->size() + other.size() + 1;\n+                auto copyStartIndex = this->size();\n+\n+                auto newBuffer = std::make_unique<char[]>(newSize);\n+                std::strcpy(newBuffer.get(),this->c_str());\n+                std::strcpy(newBuffer.get() + copyStartIndex, other.c_str());\n+                mBuffer.swap(newBuffer);\n+            }\n+\n+            return *this;\n+        }\n+\n+        MyString MyString::operator+(const char* other) const\n+        {\n+            if(other == nullptr || other[0] == 0)\n+            {\n+                return MyString(*this);\n+            }\n+            else\n+            {\n+                auto newSize = this->size() + std::strlen(other) + 1;\n+                auto copyStartIndex = this->size();\n+                auto newBuffer = std::make_unique<char[]>(newSize);\n+                std::strcpy(newBuffer.get(), mBuffer.get());\n+                std::strcpy(newBuffer.get() + copyStartIndex, other);\n+\n+                auto result = MyString(newBuffer.get());\n+                return result;\n+            }\n+        }\n+\n+        MyString MyString::operator+(const MyString& other) const\n+        {\n+            if(other.empty())\n+            {\n+                return MyString(*this);\n+            }\n+            else\n+            {\n+                auto newSize = this->size() + other.size() + 1;\n+                auto copyStartIndex = this->size();\n+\n+                auto newBuffer = std::make_unique<char[]>(newSize);\n+                std::strcpy(newBuffer.get(), mBuffer.get());\n+                std::strcpy(newBuffer.get() + copyStartIndex, other.mBuffer.get());\n+\n+                return MyString(newBuffer.get());\n+            }\n+        }\n+\n+\n+        void MyString::clearBuffer()\n+        {\n+            //TODO: what happens with the previous pointer?","path":"course3/homework-string/my_string.cpp","position":205,"original_position":205,"commit_id":"bb6464330ba3a1bc91fb8e7e268da6db4b5f0d21","original_commit_id":"bb6464330ba3a1bc91fb8e7e268da6db4b5f0d21","user":{"login":"maciekgajewski","id":1903794,"avatar_url":"https://avatars.githubusercontent.com/u/1903794?v=3","gravatar_id":"","url":"https://api.github.com/users/maciekgajewski","html_url":"https://github.com/maciekgajewski","followers_url":"https://api.github.com/users/maciekgajewski/followers","following_url":"https://api.github.com/users/maciekgajewski/following{/other_user}","gists_url":"https://api.github.com/users/maciekgajewski/gists{/gist_id}","starred_url":"https://api.github.com/users/maciekgajewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maciekgajewski/subscriptions","organizations_url":"https://api.github.com/users/maciekgajewski/orgs","repos_url":"https://api.github.com/users/maciekgajewski/repos","events_url":"https://api.github.com/users/maciekgajewski/events{/privacy}","received_events_url":"https://api.github.com/users/maciekgajewski/received_events","type":"User","site_admin":false},"body":"What \"previous pointer\" do you have in mind?","created_at":"2016-05-29T19:03:35Z","updated_at":"2016-05-29T19:03:35Z","html_url":"https://github.com/maciekgajewski/c-excercises/pull/30#discussion_r65009864","pull_request_url":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30","_links":{"self":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/comments/65009864"},"html":{"href":"https://github.com/maciekgajewski/c-excercises/pull/30#discussion_r65009864"},"pull_request":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30"}}},"pull_request":{"url":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30","id":71827844,"html_url":"https://github.com/maciekgajewski/c-excercises/pull/30","diff_url":"https://github.com/maciekgajewski/c-excercises/pull/30.diff","patch_url":"https://github.com/maciekgajewski/c-excercises/pull/30.patch","issue_url":"https://api.github.com/repos/maciekgajewski/c-excercises/issues/30","number":30,"state":"open","locked":false,"title":"Homework cc","user":{"login":"cc-catch","id":15933125,"avatar_url":"https://avatars.githubusercontent.com/u/15933125?v=3","gravatar_id":"","url":"https://api.github.com/users/cc-catch","html_url":"https://github.com/cc-catch","followers_url":"https://api.github.com/users/cc-catch/followers","following_url":"https://api.github.com/users/cc-catch/following{/other_user}","gists_url":"https://api.github.com/users/cc-catch/gists{/gist_id}","starred_url":"https://api.github.com/users/cc-catch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cc-catch/subscriptions","organizations_url":"https://api.github.com/users/cc-catch/orgs","repos_url":"https://api.github.com/users/cc-catch/repos","events_url":"https://api.github.com/users/cc-catch/events{/privacy}","received_events_url":"https://api.github.com/users/cc-catch/received_events","type":"User","site_admin":false},"body":"test & initial scratch","created_at":"2016-05-29T13:54:29Z","updated_at":"2016-05-29T19:03:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fb63dd12dc8594e4663fc7625b71a8b6a25f0106","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30/commits","review_comments_url":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30/comments","review_comment_url":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/comments{/number}","comments_url":"https://api.github.com/repos/maciekgajewski/c-excercises/issues/30/comments","statuses_url":"https://api.github.com/repos/maciekgajewski/c-excercises/statuses/bb6464330ba3a1bc91fb8e7e268da6db4b5f0d21","head":{"label":"cc-catch:homework-cc","ref":"homework-cc","sha":"bb6464330ba3a1bc91fb8e7e268da6db4b5f0d21","user":{"login":"cc-catch","id":15933125,"avatar_url":"https://avatars.githubusercontent.com/u/15933125?v=3","gravatar_id":"","url":"https://api.github.com/users/cc-catch","html_url":"https://github.com/cc-catch","followers_url":"https://api.github.com/users/cc-catch/followers","following_url":"https://api.github.com/users/cc-catch/following{/other_user}","gists_url":"https://api.github.com/users/cc-catch/gists{/gist_id}","starred_url":"https://api.github.com/users/cc-catch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cc-catch/subscriptions","organizations_url":"https://api.github.com/users/cc-catch/orgs","repos_url":"https://api.github.com/users/cc-catch/repos","events_url":"https://api.github.com/users/cc-catch/events{/privacy}","received_events_url":"https://api.github.com/users/cc-catch/received_events","type":"User","site_admin":false},"repo":{"id":59149195,"name":"c-excercises","full_name":"cc-catch/c-excercises","owner":{"login":"cc-catch","id":15933125,"avatar_url":"https://avatars.githubusercontent.com/u/15933125?v=3","gravatar_id":"","url":"https://api.github.com/users/cc-catch","html_url":"https://github.com/cc-catch","followers_url":"https://api.github.com/users/cc-catch/followers","following_url":"https://api.github.com/users/cc-catch/following{/other_user}","gists_url":"https://api.github.com/users/cc-catch/gists{/gist_id}","starred_url":"https://api.github.com/users/cc-catch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cc-catch/subscriptions","organizations_url":"https://api.github.com/users/cc-catch/orgs","repos_url":"https://api.github.com/users/cc-catch/repos","events_url":"https://api.github.com/users/cc-catch/events{/privacy}","received_events_url":"https://api.github.com/users/cc-catch/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cc-catch/c-excercises","description":"\"C++ for Python developers\"","fork":true,"url":"https://api.github.com/repos/cc-catch/c-excercises","forks_url":"https://api.github.com/repos/cc-catch/c-excercises/forks","keys_url":"https://api.github.com/repos/cc-catch/c-excercises/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cc-catch/c-excercises/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cc-catch/c-excercises/teams","hooks_url":"https://api.github.com/repos/cc-catch/c-excercises/hooks","issue_events_url":"https://api.github.com/repos/cc-catch/c-excercises/issues/events{/number}","events_url":"https://api.github.com/repos/cc-catch/c-excercises/events","assignees_url":"https://api.github.com/repos/cc-catch/c-excercises/assignees{/user}","branches_url":"https://api.github.com/repos/cc-catch/c-excercises/branches{/branch}","tags_url":"https://api.github.com/repos/cc-catch/c-excercises/tags","blobs_url":"https://api.github.com/repos/cc-catch/c-excercises/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cc-catch/c-excercises/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cc-catch/c-excercises/git/refs{/sha}","trees_url":"https://api.github.com/repos/cc-catch/c-excercises/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cc-catch/c-excercises/statuses/{sha}","languages_url":"https://api.github.com/repos/cc-catch/c-excercises/languages","stargazers_url":"https://api.github.com/repos/cc-catch/c-excercises/stargazers","contributors_url":"https://api.github.com/repos/cc-catch/c-excercises/contributors","subscribers_url":"https://api.github.com/repos/cc-catch/c-excercises/subscribers","subscription_url":"https://api.github.com/repos/cc-catch/c-excercises/subscription","commits_url":"https://api.github.com/repos/cc-catch/c-excercises/commits{/sha}","git_commits_url":"https://api.github.com/repos/cc-catch/c-excercises/git/commits{/sha}","comments_url":"https://api.github.com/repos/cc-catch/c-excercises/comments{/number}","issue_comment_url":"https://api.github.com/repos/cc-catch/c-excercises/issues/comments{/number}","contents_url":"https://api.github.com/repos/cc-catch/c-excercises/contents/{+path}","compare_url":"https://api.github.com/repos/cc-catch/c-excercises/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cc-catch/c-excercises/merges","archive_url":"https://api.github.com/repos/cc-catch/c-excercises/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cc-catch/c-excercises/downloads","issues_url":"https://api.github.com/repos/cc-catch/c-excercises/issues{/number}","pulls_url":"https://api.github.com/repos/cc-catch/c-excercises/pulls{/number}","milestones_url":"https://api.github.com/repos/cc-catch/c-excercises/milestones{/number}","notifications_url":"https://api.github.com/repos/cc-catch/c-excercises/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cc-catch/c-excercises/labels{/name}","releases_url":"https://api.github.com/repos/cc-catch/c-excercises/releases{/id}","deployments_url":"https://api.github.com/repos/cc-catch/c-excercises/deployments","created_at":"2016-05-18T20:33:21Z","updated_at":"2016-05-18T20:33:21Z","pushed_at":"2016-05-29T14:17:00Z","git_url":"git://github.com/cc-catch/c-excercises.git","ssh_url":"git@github.com:cc-catch/c-excercises.git","clone_url":"https://github.com/cc-catch/c-excercises.git","svn_url":"https://github.com/cc-catch/c-excercises","homepage":null,"size":196,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"maciekgajewski:master","ref":"master","sha":"d571c9700e83e73c7365c5f2e2a79aa3afbeb12f","user":{"login":"maciekgajewski","id":1903794,"avatar_url":"https://avatars.githubusercontent.com/u/1903794?v=3","gravatar_id":"","url":"https://api.github.com/users/maciekgajewski","html_url":"https://github.com/maciekgajewski","followers_url":"https://api.github.com/users/maciekgajewski/followers","following_url":"https://api.github.com/users/maciekgajewski/following{/other_user}","gists_url":"https://api.github.com/users/maciekgajewski/gists{/gist_id}","starred_url":"https://api.github.com/users/maciekgajewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maciekgajewski/subscriptions","organizations_url":"https://api.github.com/users/maciekgajewski/orgs","repos_url":"https://api.github.com/users/maciekgajewski/repos","events_url":"https://api.github.com/users/maciekgajewski/events{/privacy}","received_events_url":"https://api.github.com/users/maciekgajewski/received_events","type":"User","site_admin":false},"repo":{"id":31058584,"name":"c-excercises","full_name":"maciekgajewski/c-excercises","owner":{"login":"maciekgajewski","id":1903794,"avatar_url":"https://avatars.githubusercontent.com/u/1903794?v=3","gravatar_id":"","url":"https://api.github.com/users/maciekgajewski","html_url":"https://github.com/maciekgajewski","followers_url":"https://api.github.com/users/maciekgajewski/followers","following_url":"https://api.github.com/users/maciekgajewski/following{/other_user}","gists_url":"https://api.github.com/users/maciekgajewski/gists{/gist_id}","starred_url":"https://api.github.com/users/maciekgajewski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maciekgajewski/subscriptions","organizations_url":"https://api.github.com/users/maciekgajewski/orgs","repos_url":"https://api.github.com/users/maciekgajewski/repos","events_url":"https://api.github.com/users/maciekgajewski/events{/privacy}","received_events_url":"https://api.github.com/users/maciekgajewski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/maciekgajewski/c-excercises","description":"\"C++ for Python developers\"","fork":false,"url":"https://api.github.com/repos/maciekgajewski/c-excercises","forks_url":"https://api.github.com/repos/maciekgajewski/c-excercises/forks","keys_url":"https://api.github.com/repos/maciekgajewski/c-excercises/keys{/key_id}","collaborators_url":"https://api.github.com/repos/maciekgajewski/c-excercises/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/maciekgajewski/c-excercises/teams","hooks_url":"https://api.github.com/repos/maciekgajewski/c-excercises/hooks","issue_events_url":"https://api.github.com/repos/maciekgajewski/c-excercises/issues/events{/number}","events_url":"https://api.github.com/repos/maciekgajewski/c-excercises/events","assignees_url":"https://api.github.com/repos/maciekgajewski/c-excercises/assignees{/user}","branches_url":"https://api.github.com/repos/maciekgajewski/c-excercises/branches{/branch}","tags_url":"https://api.github.com/repos/maciekgajewski/c-excercises/tags","blobs_url":"https://api.github.com/repos/maciekgajewski/c-excercises/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/maciekgajewski/c-excercises/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/maciekgajewski/c-excercises/git/refs{/sha}","trees_url":"https://api.github.com/repos/maciekgajewski/c-excercises/git/trees{/sha}","statuses_url":"https://api.github.com/repos/maciekgajewski/c-excercises/statuses/{sha}","languages_url":"https://api.github.com/repos/maciekgajewski/c-excercises/languages","stargazers_url":"https://api.github.com/repos/maciekgajewski/c-excercises/stargazers","contributors_url":"https://api.github.com/repos/maciekgajewski/c-excercises/contributors","subscribers_url":"https://api.github.com/repos/maciekgajewski/c-excercises/subscribers","subscription_url":"https://api.github.com/repos/maciekgajewski/c-excercises/subscription","commits_url":"https://api.github.com/repos/maciekgajewski/c-excercises/commits{/sha}","git_commits_url":"https://api.github.com/repos/maciekgajewski/c-excercises/git/commits{/sha}","comments_url":"https://api.github.com/repos/maciekgajewski/c-excercises/comments{/number}","issue_comment_url":"https://api.github.com/repos/maciekgajewski/c-excercises/issues/comments{/number}","contents_url":"https://api.github.com/repos/maciekgajewski/c-excercises/contents/{+path}","compare_url":"https://api.github.com/repos/maciekgajewski/c-excercises/compare/{base}...{head}","merges_url":"https://api.github.com/repos/maciekgajewski/c-excercises/merges","archive_url":"https://api.github.com/repos/maciekgajewski/c-excercises/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/maciekgajewski/c-excercises/downloads","issues_url":"https://api.github.com/repos/maciekgajewski/c-excercises/issues{/number}","pulls_url":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls{/number}","milestones_url":"https://api.github.com/repos/maciekgajewski/c-excercises/milestones{/number}","notifications_url":"https://api.github.com/repos/maciekgajewski/c-excercises/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/maciekgajewski/c-excercises/labels{/name}","releases_url":"https://api.github.com/repos/maciekgajewski/c-excercises/releases{/id}","deployments_url":"https://api.github.com/repos/maciekgajewski/c-excercises/deployments","created_at":"2015-02-20T09:39:26Z","updated_at":"2016-05-18T20:33:13Z","pushed_at":"2016-05-29T19:02:08Z","git_url":"git://github.com/maciekgajewski/c-excercises.git","ssh_url":"git@github.com:maciekgajewski/c-excercises.git","clone_url":"https://github.com/maciekgajewski/c-excercises.git","svn_url":"https://github.com/maciekgajewski/c-excercises","homepage":null,"size":382,"stargazers_count":6,"watchers_count":6,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":18,"mirror_url":null,"open_issues_count":19,"forks":18,"open_issues":19,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30"},"html":{"href":"https://github.com/maciekgajewski/c-excercises/pull/30"},"issue":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/issues/30"},"comments":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/issues/30/comments"},"review_comments":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30/comments"},"review_comment":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/pulls/30/commits"},"statuses":{"href":"https://api.github.com/repos/maciekgajewski/c-excercises/statuses/bb6464330ba3a1bc91fb8e7e268da6db4b5f0d21"}}}}
{"actor":{"display_login":"maciekgajewski"}}