utils.h
 1  #pragma once
 2  
 3  #include <vector>
 4  #include <string>
 5  
 6  #include <workspaces-common/GuidUtils.h>
 7  #include <workspaces-common/InvokePoint.h>
 8  
 9  namespace NonLocalizable
10  {
11      const wchar_t restartedString[] = L"restarted";
12  }
13  
14  struct CommandLineArgs
15  {
16      std::wstring workspaceId;
17      InvokePoint invokePoint;
18      bool isRestarted;
19  };
20  
21  CommandLineArgs split(std::wstring s, const std::wstring& delimiter)
22  {
23      CommandLineArgs cmdArgs{};
24      cmdArgs.isRestarted = false;
25  
26      size_t pos = 0;
27      std::wstring token;
28      std::vector<std::wstring> tokens;
29      while ((pos = s.find(delimiter)) != std::wstring::npos)
30      {
31          token = s.substr(0, pos);
32          tokens.push_back(token);
33          s.erase(0, pos + delimiter.length());
34      }
35      tokens.push_back(s);
36  
37      for (const auto& token : tokens)
38      {
39          if (token == NonLocalizable::restartedString)
40          {
41              cmdArgs.isRestarted = true;
42          }
43          else
44          {
45              auto guid = GuidFromString(token);
46              if (guid.has_value())
47              {
48                  cmdArgs.workspaceId = token;
49              }
50              else
51              {
52                  try
53                  {
54                      auto invokePoint = static_cast<InvokePoint>(std::stoi(token));
55                      cmdArgs.invokePoint = invokePoint;
56                  }
57                  catch (std::exception)
58                  {
59                  }
60              }
61          }
62      }
63  
64      return cmdArgs;
65  }