src/string.cpp

changeset 212
79c5205b807c
parent 189
ac2d3e8dd110
child 236
b58d35dc5d52
equal deleted inserted replaced
211:8d35e631bef3 212:79c5205b807c
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <stdexcept>
19 #include "common.h" 20 #include "common.h"
20 #include "string.h" 21 #include "string.h"
21 22
22 str fmt (const char* fmtstr, ...) { 23 str fmt (const char* fmtstr, ...) {
23 va_list va; 24 va_list va;
157 158
158 String String::substr (long a, long b) const { 159 String String::substr (long a, long b) const {
159 if (b == -1) 160 if (b == -1)
160 b = len (); 161 b = len ();
161 162
162 return m_string.substr (a, b - a); 163 str sub;
164
165 try {
166 sub = m_string.substr (a, b - a);
167 } catch (const std::out_of_range& e) {
168 printf ("%s: %s: caught std::out_of_range, coords were: (%ld, %ld), string: `%s', length: %lu\n",
169 __func__, e.what (), a, b, chars (), (ulong) len ());
170 abort ();
171 }
172
173 return sub;
163 } 174 }

mercurial