diff options
Diffstat (limited to 'nGenEx/ContentBundle.cpp')
-rw-r--r-- | nGenEx/ContentBundle.cpp | 172 |
1 files changed, 86 insertions, 86 deletions
diff --git a/nGenEx/ContentBundle.cpp b/nGenEx/ContentBundle.cpp index ca6c8e5..b489cf8 100644 --- a/nGenEx/ContentBundle.cpp +++ b/nGenEx/ContentBundle.cpp @@ -1,15 +1,15 @@ /* Project nGenEx
- Destroyer Studios LLC
- Copyright © 1997-2006. All Rights Reserved.
+ Destroyer Studios LLC
+ Copyright © 1997-2006. All Rights Reserved.
- SUBSYSTEM: nGenEx.lib
- FILE: ContentBundle.cpp
- AUTHOR: John DiCamillo
+ SUBSYSTEM: nGenEx.lib
+ FILE: ContentBundle.cpp
+ AUTHOR: John DiCamillo
- OVERVIEW
- ========
- Chained collection of localized strings
+ OVERVIEW
+ ========
+ Chained collection of localized strings
*/
#include "MemDebug.h"
@@ -22,10 +22,10 @@ void Print(const char* fmt, ...); ContentBundle::ContentBundle(const char* bundle, Locale* locale)
{
- Text file = FindFile(bundle, locale);
- if (file.length() > 0) {
- LoadBundle(file);
- }
+ Text file = FindFile(bundle, locale);
+ if (file.length() > 0) {
+ LoadBundle(file);
+ }
}
// +--------------------------------------------------------------------+
@@ -39,7 +39,7 @@ ContentBundle::~ContentBundle() Text
ContentBundle::GetText(const char* key) const
{
- return values.find(key, Text(key));
+ return values.find(key, Text(key));
}
// +--------------------------------------------------------------------+
@@ -47,30 +47,30 @@ ContentBundle::GetText(const char* key) const Text
ContentBundle::FindFile(const char* bundle, Locale* locale)
{
- Text result;
- Text basename = Text(bundle);
- DataLoader* loader = DataLoader::GetLoader();
+ Text result;
+ Text basename = Text(bundle);
+ DataLoader* loader = DataLoader::GetLoader();
- if (loader && bundle) {
- if (locale) {
- result = basename + locale->GetFullCode() + ".txt";
+ if (loader && bundle) {
+ if (locale) {
+ result = basename + locale->GetFullCode() + ".txt";
- if (loader->FindFile(result))
- return result;
+ if (loader->FindFile(result))
+ return result;
- result = basename + "_" + locale->GetLanguage() + ".txt";
+ result = basename + "_" + locale->GetLanguage() + ".txt";
- if (loader->FindFile(result))
- return result;
- }
+ if (loader->FindFile(result))
+ return result;
+ }
- result = basename + ".txt";
+ result = basename + ".txt";
- if (loader->FindFile(result))
- return result;
- }
+ if (loader->FindFile(result))
+ return result;
+ }
- return Text();
+ return Text();
}
// +--------------------------------------------------------------------+
@@ -78,60 +78,60 @@ ContentBundle::FindFile(const char* bundle, Locale* locale) void
ContentBundle::LoadBundle(const char* filename)
{
- DataLoader* loader = DataLoader::GetLoader();
- if (loader && filename && *filename) {
- BYTE* buffer = 0;
- loader->LoadBuffer(filename, buffer, true, true);
- if (buffer && *buffer) {
- char key[1024];
- char val[2048];
- char* p = (char*) buffer;
- int s = 0, ik = 0, iv = 0;
-
- key[0] = 0;
- val[0] = 0;
-
- while (*p) {
- if (*p == '=') {
- s = 1;
- }
- else if (*p == '\n' || *p == '\r') {
- if (key[0] && val[0])
- values.insert(Text(key).trim(), Text(val).trim());
-
- ZeroMemory(key, 1024);
- ZeroMemory(val, 2048);
- s = 0;
- ik = 0;
- iv = 0;
- }
- else if (s == 0) {
- if (!key[0]) {
- if (*p == '#') {
- s = -1; // comment
- }
- else if (!isspace(*p)) {
- key[ik++] = *p;
- }
- }
- else {
- key[ik++] = *p;
- }
- }
- else if (s == 1) {
- if (!isspace(*p)) {
- s = 2;
- val[iv++] = *p;
- }
- }
- else if (s == 2) {
- val[iv++] = *p;
- }
-
- p++;
- }
-
- loader->ReleaseBuffer(buffer);
- }
- }
+ DataLoader* loader = DataLoader::GetLoader();
+ if (loader && filename && *filename) {
+ BYTE* buffer = 0;
+ loader->LoadBuffer(filename, buffer, true, true);
+ if (buffer && *buffer) {
+ char key[1024];
+ char val[2048];
+ char* p = (char*) buffer;
+ int s = 0, ik = 0, iv = 0;
+
+ key[0] = 0;
+ val[0] = 0;
+
+ while (*p) {
+ if (*p == '=') {
+ s = 1;
+ }
+ else if (*p == '\n' || *p == '\r') {
+ if (key[0] && val[0])
+ values.insert(Text(key).trim(), Text(val).trim());
+
+ ZeroMemory(key, 1024);
+ ZeroMemory(val, 2048);
+ s = 0;
+ ik = 0;
+ iv = 0;
+ }
+ else if (s == 0) {
+ if (!key[0]) {
+ if (*p == '#') {
+ s = -1; // comment
+ }
+ else if (!isspace(*p)) {
+ key[ik++] = *p;
+ }
+ }
+ else {
+ key[ik++] = *p;
+ }
+ }
+ else if (s == 1) {
+ if (!isspace(*p)) {
+ s = 2;
+ val[iv++] = *p;
+ }
+ }
+ else if (s == 2) {
+ val[iv++] = *p;
+ }
+
+ p++;
+ }
+
+ loader->ReleaseBuffer(buffer);
+ }
+ }
}
|