summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ace/Process.cpp182
-rw-r--r--ace/Process.h103
-rw-r--r--ace/SString.cpp184
-rw-r--r--ace/SString.h103
4 files changed, 288 insertions, 284 deletions
diff --git a/ace/Process.cpp b/ace/Process.cpp
index 43023ce1349..7446a69d293 100644
--- a/ace/Process.cpp
+++ b/ace/Process.cpp
@@ -9,188 +9,6 @@
#include "ace/Process.i"
#endif /* __ACE_INLINE__ */
-ACE_Tokenizer::ACE_Tokenizer (LPTSTR buffer)
- : buffer_ (buffer),
- index_ (0),
- preserves_index_ (0),
- delimiter_index_ (0)
-{
-}
-
-int
-ACE_Tokenizer::delimiter (TCHAR d)
-{
- if (delimiter_index_ == MAX_DELIMITERS)
- return -1;
-
- delimiters_[delimiter_index_].delimiter_ = d;
- delimiters_[delimiter_index_].replace_ = 0;
- delimiter_index_++;
- return 0;
-}
-
-int
-ACE_Tokenizer::delimiter_replace (TCHAR d, TCHAR replacement)
-{
- if (delimiter_index_ == MAX_DELIMITERS)
- return -1;
-
- delimiters_[delimiter_index_].delimiter_ = d;
- delimiters_[delimiter_index_].replacement_ = replacement;
- delimiters_[delimiter_index_].replace_ = 1;
- delimiter_index_++;
- return 0;
-}
-
-int
-ACE_Tokenizer::preserve_designators (TCHAR start, TCHAR stop, int strip)
-{
- if (preserves_index_ == MAX_PRESERVES)
- return -1;
-
- preserves_[preserves_index_].start_ = start;
- preserves_[preserves_index_].stop_ = stop;
- preserves_[preserves_index_].strip_ = strip;
- preserves_index_++;
- return 0;
-}
-
-int
-ACE_Tokenizer::is_delimiter (TCHAR d, int &replace, TCHAR &r)
-{
- replace = 0;
-
- for (int x=0; x < delimiter_index_; x++)
- if (delimiters_[x].delimiter_ == d)
- {
- if (delimiters_[x].replace_)
- {
- r = delimiters_[x].replacement_;
- replace = 1;
- }
- return 1;
- }
-
- return 0;
-}
-
-int
-ACE_Tokenizer::is_preserve_designator (TCHAR start, TCHAR &stop, int &strip)
-{
- for (int x=0; x < preserves_index_; x++)
- if (preserves_[x].start_ == start)
- {
- stop = preserves_[x].stop_;
- strip = preserves_[x].strip_;
- return 1;
- }
-
- return 0;
-}
-
-LPTSTR
-ACE_Tokenizer::next (void)
-{
- // Check if the previous pass was the last one in the buffer.
- if (index_ == -1)
- {
- index_ = 0;
- return 0;
- }
-
- TCHAR replacement;
- int replace;
- LPTSTR next_token;
-
- // Skip all leading delimiters.
- while (1)
- {
- // Check for end of string.
- if (buffer_[index_] == '\0')
- {
- // If we hit EOS at the start, return 0.
- index_ = 0;
- return 0;
- }
-
- if (this->is_delimiter (buffer_[index_], replace, replacement))
- index_++;
- else
- break;
- }
-
- // When we reach this point, buffer_[index_] is a non-delimiter and
- // not EOS - the start of our next_token.
- next_token = buffer_ + index_;
-
- // A preserved region is it's own token.
- TCHAR stop;
- int strip;
- if (this->is_preserve_designator (buffer_[index_], stop, strip))
- {
- while (++index_)
- {
- if (buffer_[index_] == '\0')
- {
- index_ = -1;
- goto EXIT_LABEL;
- }
-
- if (buffer_[index_] == stop)
- break;
- }
-
- if (strip)
- {
- // Skip start preserve designator.
- next_token += 1;
- // Zap the stop preserve designator.
- buffer_[index_] = '\0';
- // Increment to the next token.
- index_++;
- }
- else
- next_token = buffer_ + index_;
-
- goto EXIT_LABEL;
- }
-
- // Step through finding the next delimiter or EOS.
- while (1)
- {
- // Advance pointer.
- index_++;
-
- // Check for delimiter.
- if (this->is_delimiter (buffer_[index_], replace, replacement))
- {
- // Replace the delimiter.
- if (replace != 0)
- buffer_[index_] = replacement;
-
- // Move the pointer up and return.
- index_++;
- goto EXIT_LABEL;
- }
-
- // A preserve designator signifies the end of this token.
- if (this->is_preserve_designator (buffer_[index_], stop, strip))
- goto EXIT_LABEL;
-
- // Check for end of string.
- if (buffer_[index_] == '\0')
- {
- index_ = -1;
- goto EXIT_LABEL;
- }
- }
-
-EXIT_LABEL:
- return next_token;
-}
-
-// ************************************************************
-
ACE_Process::ACE_Process (void)
#if !defined (ACE_WIN32)
: child_id_ (0)
diff --git a/ace/Process.h b/ace/Process.h
index 4ef98cf8741..d619c5a6614 100644
--- a/ace/Process.h
+++ b/ace/Process.h
@@ -284,108 +284,7 @@ protected:
#endif /* ACE_WIN32 */
};
-// ************************************************************
-
-class ACE_Export ACE_Tokenizer
-{
- // = TITLE
- // Tokenizer
- //
- // = DESCRIPTION
- // Tokenizes a buffer. Allows application to set delimiters and
- // preserve designators. Does not allow special characters, yet
- // (e.g., printf ("\"like a quoted string\"").
-public:
- ACE_Tokenizer (LPTSTR buffer);
- // <buffer> will be parsed.
-
- int delimiter (TCHAR d);
- // <d> is a delimiter. Returns 0 on success, -1 if there is no
- // memory left.
-
- int delimiter_replace (TCHAR d, TCHAR replacement);
- // <d> is a delimiter and, when found, will be replaced by
- // <replacement>. Returns 0 on success, -1 if there is no memory
- // left.
-
- int preserve_designators (TCHAR start, TCHAR stop, int strip=1);
- // For instance, quotes, or '(' and ')'. Returns 0 on success, -1
- // if there is no memory left. If <strip> == 1, then the preserve
- // designators will be stripped from the tokens returned by next.
-
- LPTSTR next (void);
- // Returns the next token.
-
- enum {
- MAX_DELIMITERS=16,
- MAX_PRESERVES=16
- };
-
-protected:
- int is_delimiter (TCHAR d, int &replace, TCHAR &r);
- // Returns 1 if <d> is a delimiter, 0 otherwise. If <d> should be
- // replaced with <r>, <replace> is set to 1, otherwise 0.
-
- int is_preserve_designator (TCHAR start, TCHAR &stop, int &strip);
- // If <start> is a start preserve designator, returns 1 and sets
- // <stop> to the stop designator. Returns 0 if <start> is not a
- // preserve designator.
-
-private:
- LPTSTR buffer_;
- int index_;
-
- class Preserve_Entry
- {
- // = TITLE
- // Preserve Entry
- //
- // = DESCRIPTION
- // Defines a set of characters that designate an area that
- // should not be parsed, but should be treated as a complete
- // token. For instance, in: (this is a preserve region), start
- // would be a left paren -(- and stop would be a right paren
- // -)-. The strip determines whether the designators should be
- // removed from the token.
- public:
- TCHAR start_;
- // E.g., "(".
- TCHAR stop_;
- // E.g., ")".
- int strip_;
- // Whether the designators should be removed from the token.
- };
-
- Preserve_Entry preserves_[MAX_PRESERVES];
- // The application can specify MAX_PRESERVES preserve designators.
-
- int preserves_index_;
- // Pointer to the next free spot in preserves_.
-
- class Delimiter_Entry
- {
- // = TITLE
- // Delimiter Entry
- //
- // = DESCRIPTION
- // Describes a delimiter for the tokenizer.
- public:
- TCHAR delimiter_;
- // Most commonly a space ' '.
- TCHAR replacement_;
- // What occurrences of delimiter_ should be replaced with.
- int replace_;
- // Whether replacement_ should be used. This should be replaced
- // with a technique that sets replacement_ = delimiter by
- // default. I'll do that next iteration.
- };
-
- Delimiter_Entry delimiters_[MAX_DELIMITERS];
- // The tokenizer allows MAX_DELIMITERS number of delimiters.
-
- int delimiter_index_;
- // Pointer to the next free space in delimiters_.
-};
+#include "ace/SString.h"
#if defined (__ACE_INLINE__)
#include "ace/Process.i"
diff --git a/ace/SString.cpp b/ace/SString.cpp
index 790cde96f26..4ebc6da90a3 100644
--- a/ace/SString.cpp
+++ b/ace/SString.cpp
@@ -12,6 +12,188 @@
#include "ace/SString.i"
#endif /* __ACE_INLINE__ */
+ACE_Tokenizer::ACE_Tokenizer (LPTSTR buffer)
+ : buffer_ (buffer),
+ index_ (0),
+ preserves_index_ (0),
+ delimiter_index_ (0)
+{
+}
+
+int
+ACE_Tokenizer::delimiter (TCHAR d)
+{
+ if (delimiter_index_ == MAX_DELIMITERS)
+ return -1;
+
+ delimiters_[delimiter_index_].delimiter_ = d;
+ delimiters_[delimiter_index_].replace_ = 0;
+ delimiter_index_++;
+ return 0;
+}
+
+int
+ACE_Tokenizer::delimiter_replace (TCHAR d, TCHAR replacement)
+{
+ if (delimiter_index_ == MAX_DELIMITERS)
+ return -1;
+
+ delimiters_[delimiter_index_].delimiter_ = d;
+ delimiters_[delimiter_index_].replacement_ = replacement;
+ delimiters_[delimiter_index_].replace_ = 1;
+ delimiter_index_++;
+ return 0;
+}
+
+int
+ACE_Tokenizer::preserve_designators (TCHAR start, TCHAR stop, int strip)
+{
+ if (preserves_index_ == MAX_PRESERVES)
+ return -1;
+
+ preserves_[preserves_index_].start_ = start;
+ preserves_[preserves_index_].stop_ = stop;
+ preserves_[preserves_index_].strip_ = strip;
+ preserves_index_++;
+ return 0;
+}
+
+int
+ACE_Tokenizer::is_delimiter (TCHAR d, int &replace, TCHAR &r)
+{
+ replace = 0;
+
+ for (int x=0; x < delimiter_index_; x++)
+ if (delimiters_[x].delimiter_ == d)
+ {
+ if (delimiters_[x].replace_)
+ {
+ r = delimiters_[x].replacement_;
+ replace = 1;
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
+int
+ACE_Tokenizer::is_preserve_designator (TCHAR start, TCHAR &stop, int &strip)
+{
+ for (int x=0; x < preserves_index_; x++)
+ if (preserves_[x].start_ == start)
+ {
+ stop = preserves_[x].stop_;
+ strip = preserves_[x].strip_;
+ return 1;
+ }
+
+ return 0;
+}
+
+LPTSTR
+ACE_Tokenizer::next (void)
+{
+ // Check if the previous pass was the last one in the buffer.
+ if (index_ == -1)
+ {
+ index_ = 0;
+ return 0;
+ }
+
+ TCHAR replacement;
+ int replace;
+ LPTSTR next_token;
+
+ // Skip all leading delimiters.
+ while (1)
+ {
+ // Check for end of string.
+ if (buffer_[index_] == '\0')
+ {
+ // If we hit EOS at the start, return 0.
+ index_ = 0;
+ return 0;
+ }
+
+ if (this->is_delimiter (buffer_[index_], replace, replacement))
+ index_++;
+ else
+ break;
+ }
+
+ // When we reach this point, buffer_[index_] is a non-delimiter and
+ // not EOS - the start of our next_token.
+ next_token = buffer_ + index_;
+
+ // A preserved region is it's own token.
+ TCHAR stop;
+ int strip;
+ if (this->is_preserve_designator (buffer_[index_], stop, strip))
+ {
+ while (++index_)
+ {
+ if (buffer_[index_] == '\0')
+ {
+ index_ = -1;
+ goto EXIT_LABEL;
+ }
+
+ if (buffer_[index_] == stop)
+ break;
+ }
+
+ if (strip)
+ {
+ // Skip start preserve designator.
+ next_token += 1;
+ // Zap the stop preserve designator.
+ buffer_[index_] = '\0';
+ // Increment to the next token.
+ index_++;
+ }
+ else
+ next_token = buffer_ + index_;
+
+ goto EXIT_LABEL;
+ }
+
+ // Step through finding the next delimiter or EOS.
+ while (1)
+ {
+ // Advance pointer.
+ index_++;
+
+ // Check for delimiter.
+ if (this->is_delimiter (buffer_[index_], replace, replacement))
+ {
+ // Replace the delimiter.
+ if (replace != 0)
+ buffer_[index_] = replacement;
+
+ // Move the pointer up and return.
+ index_++;
+ goto EXIT_LABEL;
+ }
+
+ // A preserve designator signifies the end of this token.
+ if (this->is_preserve_designator (buffer_[index_], stop, strip))
+ goto EXIT_LABEL;
+
+ // Check for end of string.
+ if (buffer_[index_] == '\0')
+ {
+ index_ = -1;
+ goto EXIT_LABEL;
+ }
+ }
+
+EXIT_LABEL:
+ return next_token;
+}
+
+// ************************************************************
+
ACE_ALLOC_HOOK_DEFINE(ACE_CString)
char ACE_CString::NULL_CString_ = '\0';
@@ -19,6 +201,7 @@ const int ACE_CString::npos = -1;
const int ACE_SString::npos = -1;
const int ACE_WString::npos = -1;
+#if !defined (ACE_HAS_WINCE)
ostream &
operator<< (ostream &os, const ACE_CString &cs)
{
@@ -32,6 +215,7 @@ operator<< (ostream &os, const ACE_SString &ss)
os << ss.fast_rep ();
return os;
}
+#endif /* !ACE_HAS_WINCE */
ACE_WString
operator+ (const ACE_WString &s, const ACE_WString &t)
diff --git a/ace/SString.h b/ace/SString.h
index db8b02075f3..b71e33742ba 100644
--- a/ace/SString.h
+++ b/ace/SString.h
@@ -438,6 +438,109 @@ private:
ACE_Export ACE_WString operator+ (const ACE_WString &, const ACE_WString &);
+// ************************************************************
+
+class ACE_Export ACE_Tokenizer
+{
+ // = TITLE
+ // Tokenizer
+ //
+ // = DESCRIPTION
+ // Tokenizes a buffer. Allows application to set delimiters and
+ // preserve designators. Does not allow special characters, yet
+ // (e.g., printf ("\"like a quoted string\"").
+public:
+ ACE_Tokenizer (LPTSTR buffer);
+ // <buffer> will be parsed.
+
+ int delimiter (TCHAR d);
+ // <d> is a delimiter. Returns 0 on success, -1 if there is no
+ // memory left.
+
+ int delimiter_replace (TCHAR d, TCHAR replacement);
+ // <d> is a delimiter and, when found, will be replaced by
+ // <replacement>. Returns 0 on success, -1 if there is no memory
+ // left.
+
+ int preserve_designators (TCHAR start, TCHAR stop, int strip=1);
+ // For instance, quotes, or '(' and ')'. Returns 0 on success, -1
+ // if there is no memory left. If <strip> == 1, then the preserve
+ // designators will be stripped from the tokens returned by next.
+
+ LPTSTR next (void);
+ // Returns the next token.
+
+ enum {
+ MAX_DELIMITERS=16,
+ MAX_PRESERVES=16
+ };
+
+protected:
+ int is_delimiter (TCHAR d, int &replace, TCHAR &r);
+ // Returns 1 if <d> is a delimiter, 0 otherwise. If <d> should be
+ // replaced with <r>, <replace> is set to 1, otherwise 0.
+
+ int is_preserve_designator (TCHAR start, TCHAR &stop, int &strip);
+ // If <start> is a start preserve designator, returns 1 and sets
+ // <stop> to the stop designator. Returns 0 if <start> is not a
+ // preserve designator.
+
+private:
+ LPTSTR buffer_;
+ int index_;
+
+ class Preserve_Entry
+ {
+ // = TITLE
+ // Preserve Entry
+ //
+ // = DESCRIPTION
+ // Defines a set of characters that designate an area that
+ // should not be parsed, but should be treated as a complete
+ // token. For instance, in: (this is a preserve region), start
+ // would be a left paren -(- and stop would be a right paren
+ // -)-. The strip determines whether the designators should be
+ // removed from the token.
+ public:
+ TCHAR start_;
+ // E.g., "(".
+ TCHAR stop_;
+ // E.g., ")".
+ int strip_;
+ // Whether the designators should be removed from the token.
+ };
+
+ Preserve_Entry preserves_[MAX_PRESERVES];
+ // The application can specify MAX_PRESERVES preserve designators.
+
+ int preserves_index_;
+ // Pointer to the next free spot in preserves_.
+
+ class Delimiter_Entry
+ {
+ // = TITLE
+ // Delimiter Entry
+ //
+ // = DESCRIPTION
+ // Describes a delimiter for the tokenizer.
+ public:
+ TCHAR delimiter_;
+ // Most commonly a space ' '.
+ TCHAR replacement_;
+ // What occurrences of delimiter_ should be replaced with.
+ int replace_;
+ // Whether replacement_ should be used. This should be replaced
+ // with a technique that sets replacement_ = delimiter by
+ // default. I'll do that next iteration.
+ };
+
+ Delimiter_Entry delimiters_[MAX_DELIMITERS];
+ // The tokenizer allows MAX_DELIMITERS number of delimiters.
+
+ int delimiter_index_;
+ // Pointer to the next free space in delimiters_.
+};
+
#if defined (__ACE_INLINE__)
#include "ace/SString.i"
#endif /* __ACE_INLINE__ */