-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nnnn add extra functionality to string converter
adding three new converters to operate over strings: - first one supports padding text with a set of characters - second one removes trailing zeroes from a string - third one trims spaces from text several files are just the usual boilerplate code. Added some comments in the code Diffs= 2240d091f8 Nnnn add extra functionality to string converter (#8876) Co-authored-by: hernan <[email protected]>
- Loading branch information
Showing
19 changed files
with
570 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5574d9e34ecfa4ba2790ff928e839fa854aa5b60 | ||
2240d091f8d55ae4ef75409109684d9ca68b2450 |
40 changes: 40 additions & 0 deletions
40
dev/defs/data_bind/converters/data_converter_string_pad.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{ | ||
"name": "DataConverterStringPad", | ||
"key": { | ||
"int": 530, | ||
"string": "dataconverterstringpad" | ||
}, | ||
"extends": "data_bind/converters/data_converter.json", | ||
"properties": { | ||
"length": { | ||
"type": "uint", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 743, | ||
"string": "length" | ||
}, | ||
"description": "Applies text pad depending on the padType until it reaches the given length", | ||
"bindable": true | ||
}, | ||
"text": { | ||
"type": "String", | ||
"initialValue": "''", | ||
"key": { | ||
"int": 744, | ||
"string": "text" | ||
}, | ||
"description": "String to apply as pad.", | ||
"bindable": true | ||
}, | ||
"padType": { | ||
"type": "uint", | ||
"initialValue": "0", | ||
"key": { | ||
"int": 745, | ||
"string": "padtype" | ||
}, | ||
"description": "Pad type, 0 is start, 1 is end", | ||
"bindable": true | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dev/defs/data_bind/converters/data_converter_string_remove_zeros.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "DataConverterStringRemoveZeros", | ||
"key": { | ||
"int": 531, | ||
"string": "dataconverterstringremovezeros" | ||
}, | ||
"extends": "data_bind/converters/data_converter.json" | ||
} |
20 changes: 20 additions & 0 deletions
20
dev/defs/data_bind/converters/data_converter_string_trim.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "DataConverterStringTrim", | ||
"key": { | ||
"int": 532, | ||
"string": "dataconverterstringtrim" | ||
}, | ||
"extends": "data_bind/converters/data_converter.json", | ||
"properties": { | ||
"trimType": { | ||
"type": "uint", | ||
"initialValue": "1", | ||
"key": { | ||
"int": 746, | ||
"string": "trimtype" | ||
}, | ||
"description": "Trim type, 0 is none, 1 is start, 2 is end, 3 is all", | ||
"bindable": true | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
include/rive/data_bind/converters/data_converter_string_pad.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_STRING_PAD_HPP_ | ||
#define _RIVE_DATA_CONVERTER_STRING_PAD_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_string_pad_base.hpp" | ||
#include "rive/data_bind/data_bind.hpp" | ||
#include "rive/data_bind/data_values/data_value_string.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverterStringPad : public DataConverterStringPadBase | ||
{ | ||
public: | ||
DataValue* convert(DataValue* value, DataBind* dataBind) override; | ||
DataType outputType() override { return DataType::string; }; | ||
|
||
private: | ||
DataValueString m_output; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
20 changes: 20 additions & 0 deletions
20
include/rive/data_bind/converters/data_converter_string_remove_zeros.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_STRING_REMOVE_ZEROS_HPP_ | ||
#define _RIVE_DATA_CONVERTER_STRING_REMOVE_ZEROS_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_string_remove_zeros_base.hpp" | ||
#include "rive/data_bind/data_bind.hpp" | ||
#include "rive/data_bind/data_values/data_value_string.hpp" | ||
#include <stdio.h> | ||
namespace rive | ||
{ | ||
class DataConverterStringRemoveZeros : public DataConverterStringRemoveZerosBase | ||
{ | ||
public: | ||
DataValue* convert(DataValue* value, DataBind* dataBind) override; | ||
DataType outputType() override { return DataType::string; }; | ||
|
||
private: | ||
DataValueString m_output; | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
46 changes: 46 additions & 0 deletions
46
include/rive/data_bind/converters/data_converter_string_trim.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_STRING_TRIM_HPP_ | ||
#define _RIVE_DATA_CONVERTER_STRING_TRIM_HPP_ | ||
#include "rive/generated/data_bind/converters/data_converter_string_trim_base.hpp" | ||
#include "rive/data_bind/data_bind.hpp" | ||
#include "rive/data_bind/data_values/data_value_string.hpp" | ||
#include "rive/trim_type.hpp" | ||
#include <stdio.h> | ||
#include <algorithm> | ||
#include <cctype> | ||
#include <locale> | ||
namespace rive | ||
{ | ||
class DataConverterStringTrim : public DataConverterStringTrimBase | ||
{ | ||
public: | ||
DataValue* convert(DataValue* value, DataBind* dataBind) override; | ||
DataType outputType() override { return DataType::string; }; | ||
TrimType trimValue() { return (TrimType)trimType(); } | ||
|
||
private: | ||
DataValueString m_output; | ||
inline void ltrim(std::string& s) | ||
{ | ||
s.erase(s.begin(), | ||
std::find_if(s.begin(), s.end(), [](unsigned char ch) { | ||
return !std::isspace(ch); | ||
})); | ||
} | ||
|
||
inline void rtrim(std::string& s) | ||
{ | ||
s.erase(std::find_if(s.rbegin(), | ||
s.rend(), | ||
[](unsigned char ch) { return !std::isspace(ch); }) | ||
.base(), | ||
s.end()); | ||
} | ||
inline void trim(std::string& s) | ||
{ | ||
rtrim(s); | ||
ltrim(s); | ||
} | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
include/rive/generated/data_bind/converters/data_converter_string_pad_base.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#ifndef _RIVE_DATA_CONVERTER_STRING_PAD_BASE_HPP_ | ||
#define _RIVE_DATA_CONVERTER_STRING_PAD_BASE_HPP_ | ||
#include <string> | ||
#include "rive/core/field_types/core_string_type.hpp" | ||
#include "rive/core/field_types/core_uint_type.hpp" | ||
#include "rive/data_bind/converters/data_converter.hpp" | ||
namespace rive | ||
{ | ||
class DataConverterStringPadBase : public DataConverter | ||
{ | ||
protected: | ||
typedef DataConverter Super; | ||
|
||
public: | ||
static const uint16_t typeKey = 530; | ||
|
||
/// Helper to quickly determine if a core object extends another without | ||
/// RTTI at runtime. | ||
bool isTypeOf(uint16_t typeKey) const override | ||
{ | ||
switch (typeKey) | ||
{ | ||
case DataConverterStringPadBase::typeKey: | ||
case DataConverterBase::typeKey: | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
uint16_t coreType() const override { return typeKey; } | ||
|
||
static const uint16_t lengthPropertyKey = 743; | ||
static const uint16_t textPropertyKey = 744; | ||
static const uint16_t padTypePropertyKey = 745; | ||
|
||
protected: | ||
uint32_t m_Length = 1; | ||
std::string m_Text = ""; | ||
uint32_t m_PadType = 0; | ||
|
||
public: | ||
inline uint32_t length() const { return m_Length; } | ||
void length(uint32_t value) | ||
{ | ||
if (m_Length == value) | ||
{ | ||
return; | ||
} | ||
m_Length = value; | ||
lengthChanged(); | ||
} | ||
|
||
inline const std::string& text() const { return m_Text; } | ||
void text(std::string value) | ||
{ | ||
if (m_Text == value) | ||
{ | ||
return; | ||
} | ||
m_Text = value; | ||
textChanged(); | ||
} | ||
|
||
inline uint32_t padType() const { return m_PadType; } | ||
void padType(uint32_t value) | ||
{ | ||
if (m_PadType == value) | ||
{ | ||
return; | ||
} | ||
m_PadType = value; | ||
padTypeChanged(); | ||
} | ||
|
||
Core* clone() const override; | ||
void copy(const DataConverterStringPadBase& object) | ||
{ | ||
m_Length = object.m_Length; | ||
m_Text = object.m_Text; | ||
m_PadType = object.m_PadType; | ||
DataConverter::copy(object); | ||
} | ||
|
||
bool deserialize(uint16_t propertyKey, BinaryReader& reader) override | ||
{ | ||
switch (propertyKey) | ||
{ | ||
case lengthPropertyKey: | ||
m_Length = CoreUintType::deserialize(reader); | ||
return true; | ||
case textPropertyKey: | ||
m_Text = CoreStringType::deserialize(reader); | ||
return true; | ||
case padTypePropertyKey: | ||
m_PadType = CoreUintType::deserialize(reader); | ||
return true; | ||
} | ||
return DataConverter::deserialize(propertyKey, reader); | ||
} | ||
|
||
protected: | ||
virtual void lengthChanged() {} | ||
virtual void textChanged() {} | ||
virtual void padTypeChanged() {} | ||
}; | ||
} // namespace rive | ||
|
||
#endif |
Oops, something went wrong.