ScummVM API documentation
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 "ags/engine/ac/dynobj/cc_script_object.h"
26#include "ags/shared/util/string.h"
27
28namespace AGS3 {
29
30// Check that a supplied buffer from a text script function was not null
31#define VALIDATE_STRING(strin) if (!strin) quit("!String argument was null: make sure you pass a string buffer")
32
33const char *CreateNewScriptString(const char *text);
34inline const char *CreateNewScriptString(const AGS::Shared::String &text) { return CreateNewScriptString(text.GetCStr()); }
35char *CreateNewScriptString(size_t buf_len); // FIXME, unsafe to expose raw buf like this
36
37int String_IsNullOrEmpty(const char *thisString);
38const char *String_Copy(const char *srcString);
39const char *String_Append(const char *thisString, const char *extrabit);
40const char *String_AppendChar(const char *thisString, int extraOne);
41const char *String_ReplaceCharAt(const char *thisString, int index, int newChar);
42const char *String_Truncate(const char *thisString, int length);
43const char *String_Substring(const char *thisString, int index, int length);
44int String_CompareTo(const char *thisString, const char *otherString, bool caseSensitive);
45int String_StartsWith(const char *thisString, const char *checkForString, bool caseSensitive);
46int String_EndsWith(const char *thisString, const char *checkForString, bool caseSensitive);
47const char *String_Replace(const char *thisString, const char *lookForText, const char *replaceWithText, bool caseSensitive);
48const char *String_LowerCase(const char *thisString);
49const char *String_UpperCase(const char *thisString);
50int String_GetChars(const char *texx, int index);
51int StringToInt(const char *stino);
52int StrContains(const char *s1, const char *s2);
53
54//=============================================================================
55
56class SplitLines;
57// Break up the text into lines restricted by the given width;
58// returns number of lines, or 0 if text cannot be split well to fit in this width.
59// Does additional processing, like removal of voice-over tags and text reversal if right-to-left text display is on.
60// Optionally applies text direction rules (apply_direction param), otherwise leaves left-to-right always.
61size_t break_up_text_into_lines(const char *todis, bool apply_direction, SplitLines &lines, int wii, int fonnt, size_t max_lines = -1);
62inline size_t break_up_text_into_lines(const char *todis, SplitLines &lines, int wii, int fonnt, size_t max_lines = -1) {
63 return break_up_text_into_lines(todis, true, lines, wii, fonnt, max_lines);
64}
65// Checks the capacity of an old-style script string buffer.
66// Commonly this should return MAX_MAXSTRLEN, but there are
67// cases when the buffer is a field inside one of the game structs,
68// in which case this returns that field's capacity.
69size_t check_scstrcapacity(const char *ptr);
70// This function reports that a legacy script string was modified,
71// and checks if it is an object's field in order to sync with any contemporary
72// properties.
73void commit_scstr_update(const char *ptr);
74// Tries if the input string contains a voice-over token ("&N"),
75// *optionally* fills the voice_num value (if the valid int pointer is passed),
76// and returns the pointer to the text portion after the token.
77// If returned pointer equals input pointer, that means that there was no token.
78// voice_num must be > 0 for a valid token, it's assigned 0 if no token was found,
79// or if there have been a parsing error.
80const char *parse_voiceover_token(const char *text, int *voice_num);
81
82} // namespace AGS3
83
84#endif