ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
string.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef AGS_ENGINE_AC_STRING_H
23 #define AGS_ENGINE_AC_STRING_H
24 
25 //include <stdarg.h>
26 #include "ags/engine/ac/dynobj/cc_script_object.h"
27 #include "ags/shared/util/string.h"
28 
29 namespace AGS3 {
30 
31 // Check that a supplied buffer from a text script function was not null
32 #define VALIDATE_STRING(strin) if (!strin) quit("!String argument was null: make sure you pass a string buffer")
33 
34 const char *CreateNewScriptString(const char *text);
35 inline const char *CreateNewScriptString(const AGS::Shared::String &text) { return CreateNewScriptString(text.GetCStr()); }
36 char *CreateNewScriptString(size_t buf_len); // FIXME, unsafe to expose raw buf like this
37 
38 int String_IsNullOrEmpty(const char *thisString);
39 const char *String_Copy(const char *srcString);
40 const char *String_Append(const char *thisString, const char *extrabit);
41 const char *String_AppendChar(const char *thisString, int extraOne);
42 const char *String_ReplaceCharAt(const char *thisString, int index, int newChar);
43 const char *String_Truncate(const char *thisString, int length);
44 const char *String_Substring(const char *thisString, int index, int length);
45 int String_CompareTo(const char *thisString, const char *otherString, bool caseSensitive);
46 int String_StartsWith(const char *thisString, const char *checkForString, bool caseSensitive);
47 int String_EndsWith(const char *thisString, const char *checkForString, bool caseSensitive);
48 const char *String_Replace(const char *thisString, const char *lookForText, const char *replaceWithText, bool caseSensitive);
49 const char *String_LowerCase(const char *thisString);
50 const char *String_UpperCase(const char *thisString);
51 int String_GetChars(const char *texx, int index);
52 int StringToInt(const char *stino);
53 int StrContains(const char *s1, const char *s2);
54 
55 //=============================================================================
56 
57 class SplitLines;
58 // Break up the text into lines restricted by the given width;
59 // returns number of lines, or 0 if text cannot be split well to fit in this width.
60 // Does additional processing, like removal of voice-over tags and text reversal if right-to-left text display is on.
61 // Optionally applies text direction rules (apply_direction param), otherwise leaves left-to-right always.
62 size_t break_up_text_into_lines(const char *todis, bool apply_direction, SplitLines &lines, int wii, int fonnt, size_t max_lines = -1);
63 inline size_t break_up_text_into_lines(const char *todis, SplitLines &lines, int wii, int fonnt, size_t max_lines = -1) {
64  return break_up_text_into_lines(todis, true, lines, wii, fonnt, max_lines);
65 }
66 // Checks the capacity of an old-style script string buffer.
67 // Commonly this should return MAX_MAXSTRLEN, but there are
68 // cases when the buffer is a field inside one of the game structs,
69 // in which case this returns that field's capacity.
70 size_t check_scstrcapacity(const char *ptr);
71 // This function reports that a legacy script string was modified,
72 // and checks if it is an object's field in order to sync with any contemporary
73 // properties.
74 void commit_scstr_update(const char *ptr);
75 // Tries if the input string contains a voice-over token ("&N"),
76 // *optionally* fills the voice_num value (if the valid int pointer is passed),
77 // and returns the pointer to the text portion after the token.
78 // If returned pointer equals input pointer, that means that there was no token.
79 // voice_num must be > 0 for a valid token, it's assigned 0 if no token was found,
80 // or if there have been a parsing error.
81 const char *parse_voiceover_token(const char *text, int *voice_num);
82 
83 } // namespace AGS3
84 
85 #endif
Definition: ags.h:40