Преглед на файлове

Use the string-utils library for tokenize.

Sam Jaffe преди 5 години
родител
ревизия
2dbebe2793
променени са 4 файла, в които са добавени 53 реда и са изтрити 18 реда
  1. 3 0
      .gitmodules
  2. 47 0
      cli.xcodeproj/project.pbxproj
  3. 1 0
      external/string-utils
  4. 2 18
      src/cli.cxx

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "external/string-utils"]
+	path = external/string-utils
+	url = ssh://git@gogs.sjaffe.name:3000/sjjaffe/cpp-string-utils.git

+ 47 - 0
cli.xcodeproj/project.pbxproj

@@ -11,6 +11,7 @@
 		CDC748E5253136FD008D9D1D /* cli.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDC748E2253136FD008D9D1D /* cli.cxx */; };
 		CDC748E725313CBC008D9D1D /* cli_test.cxx in Sources */ = {isa = PBXBuildFile; fileRef = CDC748E625313CBC008D9D1D /* cli_test.cxx */; };
 		CDC748E925313D81008D9D1D /* GoogleMock.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CDC748B425313553008D9D1D /* GoogleMock.framework */; };
+		CDC748F4253141AF008D9D1D /* libstring-utils.a in Frameworks */ = {isa = PBXBuildFile; fileRef = CDC748F125314196008D9D1D /* libstring-utils.a */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -49,6 +50,20 @@
 			remoteGlobalIDString = CDC748A42531353C008D9D1D;
 			remoteInfo = cli;
 		};
+		CDC748F025314196008D9D1D /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CDC748EA25314195008D9D1D /* string-utils.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = CD266862252FF4B600B3E667;
+			remoteInfo = "string-utils";
+		};
+		CDC748F225314196008D9D1D /* PBXContainerItemProxy */ = {
+			isa = PBXContainerItemProxy;
+			containerPortal = CDC748EA25314195008D9D1D /* string-utils.xcodeproj */;
+			proxyType = 2;
+			remoteGlobalIDString = CD266886252FFAAE00B3E667;
+			remoteInfo = "string_utils-test";
+		};
 /* End PBXContainerItemProxy section */
 
 /* Begin PBXFileReference section */
@@ -59,6 +74,7 @@
 		CDC748C625313592008D9D1D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		CDC748E2253136FD008D9D1D /* cli.cxx */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cli.cxx; sourceTree = "<group>"; };
 		CDC748E625313CBC008D9D1D /* cli_test.cxx */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cli_test.cxx; sourceTree = "<group>"; };
+		CDC748EA25314195008D9D1D /* string-utils.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "string-utils.xcodeproj"; path = "external/string-utils/string-utils.xcodeproj"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -66,6 +82,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				CDC748F4253141AF008D9D1D /* libstring-utils.a in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -84,6 +101,7 @@
 		CDC7489C2531353C008D9D1D = {
 			isa = PBXGroup;
 			children = (
+				CDC748EA25314195008D9D1D /* string-utils.xcodeproj */,
 				CDC748AC25313553008D9D1D /* GoogleMock.xcodeproj */,
 				CDC748BD25313587008D9D1D /* cli */,
 				CDC748BB2531357C008D9D1D /* src */,
@@ -145,6 +163,15 @@
 			name = Frameworks;
 			sourceTree = "<group>";
 		};
+		CDC748EB25314195008D9D1D /* Products */ = {
+			isa = PBXGroup;
+			children = (
+				CDC748F125314196008D9D1D /* libstring-utils.a */,
+				CDC748F325314196008D9D1D /* string_utils-test.xctest */,
+			);
+			name = Products;
+			sourceTree = "<group>";
+		};
 /* End PBXGroup section */
 
 /* Begin PBXHeadersBuildPhase section */
@@ -226,6 +253,10 @@
 					ProductGroup = CDC748AD25313553008D9D1D /* Products */;
 					ProjectRef = CDC748AC25313553008D9D1D /* GoogleMock.xcodeproj */;
 				},
+				{
+					ProductGroup = CDC748EB25314195008D9D1D /* Products */;
+					ProjectRef = CDC748EA25314195008D9D1D /* string-utils.xcodeproj */;
+				},
 			);
 			projectRoot = "";
 			targets = (
@@ -264,6 +295,20 @@
 			remoteRef = CDC748B925313553008D9D1D /* PBXContainerItemProxy */;
 			sourceTree = BUILT_PRODUCTS_DIR;
 		};
+		CDC748F125314196008D9D1D /* libstring-utils.a */ = {
+			isa = PBXReferenceProxy;
+			fileType = archive.ar;
+			path = "libstring-utils.a";
+			remoteRef = CDC748F025314196008D9D1D /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
+		CDC748F325314196008D9D1D /* string_utils-test.xctest */ = {
+			isa = PBXReferenceProxy;
+			fileType = wrapper.cfbundle;
+			path = "string_utils-test.xctest";
+			remoteRef = CDC748F225314196008D9D1D /* PBXContainerItemProxy */;
+			sourceTree = BUILT_PRODUCTS_DIR;
+		};
 /* End PBXReferenceProxy section */
 
 /* Begin PBXResourcesBuildPhase section */
@@ -359,6 +404,7 @@
 				MTL_FAST_MATH = YES;
 				ONLY_ACTIVE_ARCH = YES;
 				SDKROOT = macosx;
+				SYSTEM_HEADER_SEARCH_PATHS = "external/string-utils/include";
 				USER_HEADER_SEARCH_PATHS = include;
 			};
 			name = Debug;
@@ -411,6 +457,7 @@
 				MTL_ENABLE_DEBUG_INFO = NO;
 				MTL_FAST_MATH = YES;
 				SDKROOT = macosx;
+				SYSTEM_HEADER_SEARCH_PATHS = "external/string-utils/include";
 				USER_HEADER_SEARCH_PATHS = include;
 			};
 			name = Release;

+ 1 - 0
external/string-utils

@@ -0,0 +1 @@
+Subproject commit c6d0bc05841a6e83846a6ec8352a4f477e3fd15f

+ 2 - 18
src/cli.cxx

@@ -8,23 +8,7 @@
 
 #include "cli/cli.h"
 
-#include <iostream>
-
-namespace {
-
-auto tokenize(std::string const & search, std::string const & token) {
-  std::vector<std::string> rval;
-  size_t i = 0;
-  for (size_t n = search.find(token); n != std::string::npos;
-       i = n + 1, n = search.find(token, i)) {
-    if (i == n) continue;
-    rval.emplace_back(&search[i], n - i);
-  }
-  rval.emplace_back(&search[i], search.size() - i);
-  return rval;
-}
-
-}
+#include <string_utils/tokenizer.h>
 
 namespace cli {
 
@@ -35,7 +19,7 @@ cli::cli(std::istream &in) : in_(in), callbacks_(), eof_(false) {
 void cli::run() const {
   std::string command;
   while (!eof_ && std::getline(in_, command).good()) {
-    auto views = tokenize(command, " ");
+    auto views = string_utils::split(command, " ");
     command = views.front();
     views.erase(views.begin());
     if (!callbacks_.count(command)) continue; // TODO: Error message