Vowpal Wabbit
Public Member Functions | List of all members
TextState< audit > Struct Template Reference

#include <parse_example_json.h>

Inheritance diagram for TextState< audit >:
BaseState< audit >

Public Member Functions

 TextState ()
 
BaseState< audit > * String (Context< audit > &ctx, const char *str, rapidjson::SizeType length, bool)
 
- Public Member Functions inherited from BaseState< audit >
 BaseState (const char *pname)
 
virtual BaseState< audit > * Null (Context< audit > &ctx)
 
virtual BaseState< audit > * Bool (Context< audit > &ctx, bool b)
 
virtual BaseState< audit > * Float (Context< audit > &ctx, float v)
 
virtual BaseState< audit > * Uint (Context< audit > &ctx, unsigned v)
 
virtual BaseState< audit > * StartObject (Context< audit > &ctx)
 
virtual BaseState< audit > * Key (Context< audit > &ctx, const char *str, rapidjson::SizeType len, bool)
 
virtual BaseState< audit > * EndObject (Context< audit > &ctx, rapidjson::SizeType)
 
virtual BaseState< audit > * StartArray (Context< audit > &ctx)
 
virtual BaseState< audit > * EndArray (Context< audit > &ctx, rapidjson::SizeType)
 

Additional Inherited Members

- Public Attributes inherited from BaseState< audit >
const char * name
 

Detailed Description

template<bool audit>
struct TextState< audit >

Definition at line 375 of file parse_example_json.h.

Constructor & Destructor Documentation

◆ TextState()

template<bool audit>
TextState< audit >::TextState ( )
inline

Definition at line 377 of file parse_example_json.h.

377 : BaseState<audit>("text") {}

Member Function Documentation

◆ String()

template<bool audit>
BaseState<audit>* TextState< audit >::String ( Context< audit > &  ctx,
const char *  str,
rapidjson::SizeType  length,
bool   
)
inlinevirtual

Reimplemented from BaseState< audit >.

Definition at line 379 of file parse_example_json.h.

References Context< audit >::all, Context< audit >::CurrentNamespace(), and Context< audit >::previous_state.

380  {
381  auto& ns = ctx.CurrentNamespace();
382 
383  // split into individual features
384  const char* start = str;
385  const char* end = str + length;
386  for (char* p = (char*)str; p != end; p++)
387  {
388  switch (*p)
389  {
390  // split on space and tab
391  case ' ':
392  case '\t':
393  *p = '\0';
394  if (p - start > 0)
395  ns.AddFeature(ctx.all, start);
396 
397  start = p + 1;
398  break;
399  // escape chars
400  case ':':
401  case '|':
402  *p = '_';
403  break;
404  }
405  }
406 
407  if (start < end)
408  ns.AddFeature(ctx.all, start);
409 
410  return ctx.previous_state;
411  }
Namespace< audit > & CurrentNamespace()
BaseState< audit > * previous_state

The documentation for this struct was generated from the following file: