forked from mia/Aegisub
Finished basic implementation of Athenasub::String.
Originally committed to SVN as r2436.
This commit is contained in:
parent
8a31cdfa07
commit
b81c534aab
8 changed files with 124 additions and 53 deletions
|
@ -182,6 +182,10 @@
|
|||
RelativePath=".\include\athenasub\athenawin.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\athenasub\exception.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\athenasub\interfaces.h"
|
||||
>
|
||||
|
|
|
@ -36,9 +36,10 @@
|
|||
#pragma once
|
||||
|
||||
#include "api.h"
|
||||
#include <wx/string.h>
|
||||
#include <vector>
|
||||
|
||||
class wxString;
|
||||
|
||||
namespace Athenasub {
|
||||
|
||||
typedef char Character;
|
||||
|
@ -83,13 +84,18 @@ namespace Athenasub {
|
|||
void WriteChar(const Character &src,size_t &pos);
|
||||
void WriteNumber(Character *temp,int number,int pad,size_t &pos);
|
||||
|
||||
bool AsciiCompareNoCase(const Character *src) const;
|
||||
bool IsNumber() const;
|
||||
|
||||
String Lower() const;
|
||||
String Upper() const;
|
||||
void MakeUpper();
|
||||
void MakeLower();
|
||||
//String Lower() const;
|
||||
//String Upper() const;
|
||||
//void MakeUpper();
|
||||
//void MakeLower();
|
||||
|
||||
String AsciiLower() const;
|
||||
String AsciiUpper() const;
|
||||
void AsciiMakeUpper();
|
||||
void AsciiMakeLower();
|
||||
bool AsciiCompareNoCase(const Character *src) const;
|
||||
|
||||
// Convert a string to an integer
|
||||
int ToInteger() const;
|
||||
|
|
|
@ -59,43 +59,15 @@ namespace Athenasub {
|
|||
TODO
|
||||
};
|
||||
|
||||
Exception(ExceptionList _code) : std::exception(GetMessageChar(_code)) { code = _code; }
|
||||
Exception(ExceptionList _code,const char* file,const long line) : std::exception(GetMessageFile(_code,file,line)) { code = _code; }
|
||||
Exception(ExceptionList _code);
|
||||
Exception(ExceptionList _code,const char* file,const long line);
|
||||
|
||||
//String GetMessageString() const { return String(what(),wxConvLocal); }
|
||||
int GetCode() { return code; }
|
||||
|
||||
private:
|
||||
static const char* GetMessageChar(int code)
|
||||
{
|
||||
switch (code) {
|
||||
case Unknown: return "Unknown.";
|
||||
case No_Format_Handler: return "Could not find a suitable format handler.";
|
||||
case Invalid_ActionList: return "Invalid manipulator.";
|
||||
case Section_Already_Exists: return "The specified section already exists in this model.";
|
||||
case Unknown_Format: return "The specified file format is unknown.";
|
||||
case Parse_Error: return "Parse error.";
|
||||
case Unsupported_Format_Feature: return "This feature is not supported by this format.";
|
||||
case Invalid_Token: return "Invalid type for this token.";
|
||||
case Out_Of_Range: return "Out of range.";
|
||||
case Invalid_Section: return "Invalid section.";
|
||||
case Internal_Error: return "Internal error.";
|
||||
case TODO: return "TODO";
|
||||
}
|
||||
return "Invalid code.";
|
||||
}
|
||||
|
||||
|
||||
static const char* GetMessageFile(int code,const char *file,long line)
|
||||
{
|
||||
static std::string str = GetMessageChar(code);
|
||||
str = str + " (" + file + ":";
|
||||
char buffer[16];
|
||||
_itoa_s(line,buffer,10);
|
||||
str = str + buffer + ")";
|
||||
return str.c_str();
|
||||
}
|
||||
|
||||
static const char* GetMessageChar(int code);
|
||||
static const char* GetMessageFile(int code,const char *file,long line);
|
||||
|
||||
ExceptionList code;
|
||||
};
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
//
|
||||
|
||||
#include "athenastring.h"
|
||||
#include "exception.h"
|
||||
#include <wx/string.h>
|
||||
|
||||
using namespace Athenasub;
|
||||
|
||||
|
@ -155,8 +157,7 @@ size_t String::Length() const
|
|||
|
||||
size_t String::UTF8Length() const
|
||||
{
|
||||
// TODO
|
||||
return size();
|
||||
THROW_ATHENA_EXCEPTION(Exception::TODO);
|
||||
}
|
||||
|
||||
|
||||
|
@ -197,8 +198,7 @@ bool String::StartsWith(const String& string,bool caseSensitive) const
|
|||
String tmp = substr(0,string.size());
|
||||
return compare(0,string.size(),string) == 0;
|
||||
} else {
|
||||
// TODO
|
||||
return false;
|
||||
return AsciiLower().StartsWith(string.AsciiLower(),true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -209,8 +209,7 @@ bool String::EndsWith(const String& string,bool caseSensitive) const
|
|||
size_t strSize = string.size();
|
||||
return compare(size() - strSize,strSize,string) == 0;
|
||||
} else {
|
||||
// TODO
|
||||
return false;
|
||||
return AsciiLower().EndsWith(string.AsciiLower(),true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,7 +286,15 @@ bool String::AsciiCompareNoCase(const Character *src) const
|
|||
|
||||
bool String::IsNumber() const
|
||||
{
|
||||
return false; // TODO
|
||||
for (const char *chr = c_str();*chr;chr++) {
|
||||
char cur = *chr;
|
||||
if (cur < '0' || cur > '9') {
|
||||
if (cur != '.' && cur != ',' && cur != '+' && cur != '-') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -334,6 +341,7 @@ const Character* String::StringTrim(String &str,size_t startPos)
|
|||
return StringPtrTrim(chr,str.Length(),startPos);
|
||||
}
|
||||
|
||||
/*
|
||||
String String::Lower() const
|
||||
{
|
||||
String tmp(*this);
|
||||
|
@ -349,12 +357,44 @@ String String::Upper() const {
|
|||
|
||||
void String::MakeUpper()
|
||||
{
|
||||
// TODO
|
||||
THROW_ATHENA_EXCEPTION(Exception::TODO);
|
||||
}
|
||||
|
||||
void String::MakeLower()
|
||||
{
|
||||
// TODO
|
||||
THROW_ATHENA_EXCEPTION(Exception::TODO);
|
||||
}
|
||||
*/
|
||||
|
||||
String String::AsciiLower() const
|
||||
{
|
||||
String tmp(*this);
|
||||
tmp.AsciiMakeLower();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
String String::AsciiUpper() const {
|
||||
String tmp(*this);
|
||||
tmp.AsciiMakeUpper();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void String::AsciiMakeUpper()
|
||||
{
|
||||
char* str = GetCharPointer(0);
|
||||
for (int i=0; str[i]; str++) {
|
||||
char cur = str[i];
|
||||
if (cur >= 'a' && cur <= 'z') str[i] -= 32;
|
||||
}
|
||||
}
|
||||
|
||||
void String::AsciiMakeLower()
|
||||
{
|
||||
char* str = GetCharPointer(0);
|
||||
for (int i=0; str[i]; str++) {
|
||||
char cur = str[i];
|
||||
if (cur >= 'A' && cur <= 'Z') str[i] += 32;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,3 +37,51 @@
|
|||
using namespace Athenasub;
|
||||
|
||||
|
||||
////////////////
|
||||
// Constructors
|
||||
Exception::Exception(ExceptionList _code)
|
||||
: std::exception(GetMessageChar(_code))
|
||||
{
|
||||
code = _code;
|
||||
}
|
||||
|
||||
Exception::Exception(ExceptionList _code,const char* file,const long line)
|
||||
: std::exception(GetMessageFile(_code,file,line))
|
||||
{
|
||||
code = _code;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////
|
||||
// Get message string
|
||||
const char* Exception::GetMessageChar(int code)
|
||||
{
|
||||
switch (code) {
|
||||
case Unknown: return "Unknown.";
|
||||
case No_Format_Handler: return "Could not find a suitable format handler.";
|
||||
case Invalid_ActionList: return "Invalid manipulator.";
|
||||
case Section_Already_Exists: return "The specified section already exists in this model.";
|
||||
case Unknown_Format: return "The specified file format is unknown.";
|
||||
case Parse_Error: return "Parse error.";
|
||||
case Unsupported_Format_Feature: return "This feature is not supported by this format.";
|
||||
case Invalid_Token: return "Invalid type for this token.";
|
||||
case Out_Of_Range: return "Out of range.";
|
||||
case Invalid_Section: return "Invalid section.";
|
||||
case Internal_Error: return "Internal error.";
|
||||
case TODO: return "TODO";
|
||||
}
|
||||
return "Invalid code.";
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////
|
||||
// Get the message string for the filename
|
||||
const char* Exception::GetMessageFile(int code,const char *file,long line)
|
||||
{
|
||||
static std::string str = GetMessageChar(code);
|
||||
str = str + " (" + file + ":";
|
||||
char buffer[16];
|
||||
_itoa_s(line,buffer,10);
|
||||
str = str + buffer + ")";
|
||||
return str.c_str();
|
||||
}
|
||||
|
|
|
@ -258,7 +258,7 @@ Entry FormatHandlerASS::MakeEntry(const String &data,Section section,int version
|
|||
void FormatHandlerASS::ProcessGroup(String cur,String &curGroup,int &version) {
|
||||
// Style conversion
|
||||
if (!cur.IsEmpty() && cur[0] == '[') {
|
||||
String low = cur.Lower();
|
||||
String low = cur.AsciiLower();
|
||||
bool changed = true;
|
||||
|
||||
// SSA file
|
||||
|
@ -295,8 +295,8 @@ void FormatHandlerASS::ProcessGroup(String cur,String &curGroup,int &version) {
|
|||
curGroup = curGroup.Mid(1,curGroup.Length()-2);
|
||||
|
||||
// Normalize case
|
||||
curGroup.MakeLower();
|
||||
String upper = curGroup.Upper();
|
||||
curGroup.AsciiMakeLower();
|
||||
String upper = curGroup.AsciiUpper();
|
||||
bool raise = true;
|
||||
size_t len = curGroup.Length();
|
||||
for (size_t i=0;i<len;i++) {
|
||||
|
@ -314,7 +314,7 @@ void FormatHandlerASS::ProcessGroup(String cur,String &curGroup,int &version) {
|
|||
if (cur.StartsWith("scripttype:",false)) {
|
||||
String versionString = cur.Mid(11);
|
||||
versionString.TrimBoth();
|
||||
versionString.MakeLower();
|
||||
versionString.AsciiMakeLower();
|
||||
int trueVersion;
|
||||
if (versionString == "v4.00") trueVersion = 0;
|
||||
else if (versionString == "v4.00+") trueVersion = 1;
|
||||
|
|
|
@ -192,7 +192,7 @@ Athenasub::String TextFileReader::ActuallyReadLine()
|
|||
|
||||
// Remove BOM
|
||||
size_t startPos = 0;
|
||||
if (stringBuffer.Length() > 0 && stringBuffer[0] == 0xFEFF) startPos = 1;
|
||||
if (stringBuffer.Length() > 0 && stringBuffer[0] == 0xFEFF) startPos = 3;
|
||||
|
||||
// Trim
|
||||
String str = String(stringBuffer);
|
||||
|
|
|
@ -121,6 +121,7 @@
|
|||
InlineFunctionExpansion="2"
|
||||
EnableIntrinsicFunctions="true"
|
||||
FavorSizeOrSpeed="1"
|
||||
WholeProgramOptimization="false"
|
||||
AdditionalIncludeDirectories="../include"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
|
||||
RuntimeLibrary="2"
|
||||
|
@ -149,7 +150,7 @@
|
|||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
LinkTimeCodeGeneration="1"
|
||||
LinkTimeCodeGeneration="0"
|
||||
RandomizedBaseAddress="1"
|
||||
DataExecutionPrevention="0"
|
||||
TargetMachine="1"
|
||||
|
|
Loading…
Reference in a new issue