foobar2000 SDK  2015-08-03
Public Member Functions | Static Public Member Functions
titleformat_compilerabstract

#include <titleformat.h>

+ Inheritance diagram for titleformat_compiler:

Public Member Functions

virtual bool compile (titleformat_object::ptr &p_out, const char *p_spec)=0
 
void compile_force (titleformat_object::ptr &p_out, const char *p_spec)
 
void compile_safe (titleformat_object::ptr &p_out, const char *p_spec)
 
void compile_safe_ex (titleformat_object::ptr &p_out, const char *p_spec, const char *p_fallback="<ERROR>")
 
 FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT (titleformat_compiler)
 
void run (titleformat_hook *p_source, pfc::string_base &p_out, const char *p_spec)
 
- Public Member Functions inherited from service_base
template<typename outPtr_t >
bool cast (outPtr_t &outPtr)
 
virtual int service_add_ref ()=0 throw ()
 
virtual bool service_query (service_ptr_t< service_base > &p_out, const GUID &p_guid)
 
template<class T >
bool service_query_t (service_ptr_t< T > &p_out)
 
virtual int service_release ()=0 throw ()
 

Static Public Member Functions

static void remove_color_marks (const char *src, pfc::string_base &out)
 
static void remove_forbidden_chars (titleformat_text_out *p_out, const GUID &p_inputtype, const char *p_source, t_size p_source_len, const char *p_forbidden_chars)
 
static void remove_forbidden_chars_string (pfc::string_base &p_out, const char *p_source, t_size p_source_len, const char *p_forbidden_chars)
 
static void remove_forbidden_chars_string_append (pfc::string_receiver &p_out, const char *p_source, t_size p_source_len, const char *p_forbidden_chars)
 

Additional Inherited Members

- Public Types inherited from service_base
typedef service_base t_interface
 
- Protected Member Functions inherited from service_base
 service_base ()
 
 ~service_base ()
 

Detailed Description

Standard service for instantiating titleformat_object. Implemented by the core; do not reimplement. To instantiate, use static_api_ptr_t<titleformat_compiler>.

Definition at line 54 of file titleformat.h.

Member Function Documentation

virtual bool titleformat_compiler::compile ( titleformat_object::ptr &  p_out,
const char *  p_spec 
)
pure virtual

Returns false in case of a compilation error.

void titleformat_compiler::compile_force ( titleformat_object::ptr &  p_out,
const char *  p_spec 
)
inline

Throws a bug check exception when script can't be compiled. For use with hardcoded scripts only.

Definition at line 68 of file titleformat.h.

68 {if (!compile(p_out,p_spec)) uBugCheck();}
virtual bool compile(titleformat_object::ptr &p_out, const char *p_spec)=0
Returns false in case of a compilation error.
PFC_NORETURN void SHARED_EXPORT uBugCheck()
void titleformat_compiler::compile_safe ( titleformat_object::ptr &  p_out,
const char *  p_spec 
)

Should never fail, falls back to filename% in case of failure.

Definition at line 156 of file titleformat.cpp.

157 {
158  if (!compile(p_out,p_spec)) {
159  compile_force(p_out,"%filename%");
160  }
161 }
virtual bool compile(titleformat_object::ptr &p_out, const char *p_spec)=0
Returns false in case of a compilation error.
void compile_force(titleformat_object::ptr &p_out, const char *p_spec)
Throws a bug check exception when script can&#39;t be compiled. For use with hardcoded scripts only...
Definition: titleformat.h:68
void titleformat_compiler::compile_safe_ex ( titleformat_object::ptr &  p_out,
const char *  p_spec,
const char *  p_fallback = "<ERROR>" 
)

Falls back to p_fallback in case of failure.

Definition at line 176 of file titleformat.cpp.

176  {
177  if (!compile(p_out,p_spec)) compile_force(p_out,p_fallback);
178 }
virtual bool compile(titleformat_object::ptr &p_out, const char *p_spec)=0
Returns false in case of a compilation error.
void compile_force(titleformat_object::ptr &p_out, const char *p_spec)
Throws a bug check exception when script can&#39;t be compiled. For use with hardcoded scripts only...
Definition: titleformat.h:68
titleformat_compiler::FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT ( titleformat_compiler  )
void titleformat_compiler::remove_color_marks ( const char *  src,
pfc::string_base out 
)
static

Definition at line 6 of file titleformat.cpp.

7 {
8  out.reset();
9  while(*src)
10  {
11  if (*src==3)
12  {
13  src++;
14  while(*src && *src!=3) src++;
15  if (*src==3) src++;
16  }
17  else out.add_byte(*src++);
18  }
19 }
void add_byte(char c)
Definition: string_base.h:42
void titleformat_compiler::remove_forbidden_chars ( titleformat_text_out p_out,
const GUID p_inputtype,
const char *  p_source,
t_size  p_source_len,
const char *  p_forbidden_chars 
)
static

Definition at line 26 of file titleformat.cpp.

27 {
28  if (p_reserved_chars == 0 || *p_reserved_chars == 0)
29  {
30  p_out->write(p_inputtype,p_source,p_source_len);
31  }
32  else
33  {
34  p_source_len = pfc::strlen_max(p_source,p_source_len);
35  t_size index = 0;
36  t_size good_byte_count = 0;
37  while(index < p_source_len)
38  {
39  t_size delta = pfc::utf8_char_len(p_source + index,p_source_len - index);
40  if (delta == 0) break;
41  if (test_for_bad_char(p_source+index,delta,p_reserved_chars))
42  {
43  if (good_byte_count > 0) {p_out->write(p_inputtype,p_source+index-good_byte_count,good_byte_count);good_byte_count=0;}
44  p_out->write(p_inputtype,"_",1);
45  }
46  else
47  {
48  good_byte_count += delta;
49  }
50  index += delta;
51  }
52  if (good_byte_count > 0) {p_out->write(p_inputtype,p_source+index-good_byte_count,good_byte_count);good_byte_count=0;}
53  }
54 }
virtual void write(const GUID &p_inputtype, const char *p_data, t_size p_data_length=~0)=0
t_size strlen_max(const char *ptr, t_size max)
Definition: string_base.h:91
size_t t_size
Definition: int_types.h:48
static bool test_for_bad_char(const char *source, t_size source_char_len, const char *reserved)
Definition: titleformat.cpp:21
t_size utf8_char_len(const char *s, t_size max=~0)
Definition: utf8.cpp:246
void titleformat_compiler::remove_forbidden_chars_string ( pfc::string_base p_out,
const char *  p_source,
t_size  p_source_len,
const char *  p_forbidden_chars 
)
static

Definition at line 61 of file titleformat.cpp.

62 {
63  p_out.reset();
64  remove_forbidden_chars_string_append(p_out,p_source,p_source_len,p_reserved_chars);
65 }
static void remove_forbidden_chars_string_append(pfc::string_receiver &p_out, const char *p_source, t_size p_source_len, const char *p_forbidden_chars)
Definition: titleformat.cpp:56
void titleformat_compiler::remove_forbidden_chars_string_append ( pfc::string_receiver p_out,
const char *  p_source,
t_size  p_source_len,
const char *  p_forbidden_chars 
)
static

Definition at line 56 of file titleformat.cpp.

57 {
58  remove_forbidden_chars(&titleformat_text_out_impl_string(p_out),pfc::guid_null,p_source,p_source_len,p_reserved_chars);
59 }
const GUID guid_null
Definition: guid.cpp:175
static void remove_forbidden_chars(titleformat_text_out *p_out, const GUID &p_inputtype, const char *p_source, t_size p_source_len, const char *p_forbidden_chars)
Definition: titleformat.cpp:26
void titleformat_compiler::run ( titleformat_hook p_source,
pfc::string_base p_out,
const char *  p_spec 
)

Helper;.

Definition at line 149 of file titleformat.cpp.

150 {
152  if (!compile(ptr,p_spec)) p_out = "[COMPILATION ERROR]";
153  else ptr->run(p_source,p_out,NULL);
154 }
virtual bool compile(titleformat_object::ptr &p_out, const char *p_spec)=0
Returns false in case of a compilation error.

The documentation for this class was generated from the following files: