Qt 4.8
Functions
qcorecmdlineargs_p.h File Reference
#include "QtCore/qstring.h"
#include "QtCore/qstringlist.h"
#include "QtCore/qvector.h"
#include "qt_windows.h"

Go to the source code of this file.

Functions

static QStringList qCmdLineArgs (int argc, char *argv[])
 
static QStringList qWinCmdArgs (QString cmdLine)
 
template<typename Char >
static QVector< Char * > qWinCmdLine (Char *cmdParam, int length, int &argc)
 

Function Documentation

◆ qCmdLineArgs()

static QStringList qCmdLineArgs ( int  argc,
char *  argv[] 
)
inlinestatic

Definition at line 146 of file qcorecmdlineargs_p.h.

147 {
148  Q_UNUSED(argc)
149  Q_UNUSED(argv)
150  QString cmdLine = QString::fromWCharArray(GetCommandLine());
151  return qWinCmdArgs(cmdLine);
152 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
static QStringList qWinCmdArgs(QString cmdLine)
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qWinCmdArgs()

static QStringList qWinCmdArgs ( QString  cmdLine)
inlinestatic

Definition at line 133 of file qcorecmdlineargs_p.h.

Referenced by QCoreApplication::arguments(), and qCmdLineArgs().

134 {
135  QStringList args;
136 
137  int argc = 0;
138  QVector<wchar_t*> argv = qWinCmdLine<wchar_t>((wchar_t *)cmdLine.utf16(), cmdLine.length(), argc);
139  for (int a = 0; a < argc; ++a) {
140  args << QString::fromWCharArray(argv[a]);
141  }
142 
143  return args;
144 }
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
Definition: qstring.cpp:1019
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
long ASN1_INTEGER_get ASN1_INTEGER * a
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ qWinCmdLine()

template<typename Char >
static QVector<Char*> qWinCmdLine ( Char cmdParam,
int  length,
int &  argc 
)
static

Definition at line 74 of file qcorecmdlineargs_p.h.

75 {
76  QVector<Char*> argv(8);
77  Char *p = cmdParam;
78  Char *p_end = p + length;
79 
80  argc = 0;
81 
82  while (*p && p < p_end) { // parse cmd line arguments
83  while (QChar((short)(*p)).isSpace()) // skip white space
84  p++;
85  if (*p && p < p_end) { // arg starts
86  int quote;
87  Char *start, *r;
88  if (*p == Char('\"') || *p == Char('\'')) { // " or ' quote
89  quote = *p;
90  start = ++p;
91  } else {
92  quote = 0;
93  start = p;
94  }
95  r = start;
96  while (*p && p < p_end) {
97  if (quote) {
98  if (*p == quote) {
99  p++;
100  if (QChar((short)(*p)).isSpace())
101  break;
102  quote = 0;
103  }
104  }
105  if (*p == '\\') { // escape char?
106  if (*(p+1) == quote)
107  p++;
108  } else {
109  if (!quote && (*p == Char('\"') || *p == Char('\''))) { // " or ' quote
110  quote = *p++;
111  continue;
112  } else if (QChar((short)(*p)).isSpace() && !quote)
113  break;
114  }
115  if (*p)
116  *r++ = *p++;
117  }
118  if (*p && p < p_end)
119  p++;
120  *r = Char('\0');
121 
122  if (argc >= (int)argv.size()-1) // expand array
123  argv.resize(argv.size()*2);
124  argv[argc++] = start;
125  }
126  }
127  argv[argc] = 0;
128 
129  return argv;
130 }
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
ushort Char