Recognize .exp (Expect) files as Tcl
[geany-mirror.git] / scintilla / lexlib / StringCopy.h
blob1812b4e35ec49b1ce085930b542905830ee3db80
1 // Scintilla source code edit control
2 /** @file StringCopy.h
3 ** Safe string copy function which always NUL terminates.
4 ** ELEMENTS macro for determining array sizes.
5 **/
6 // Copyright 2013 by Neil Hodgson <neilh@scintilla.org>
7 // The License.txt file describes the conditions under which this software may be distributed.
9 #ifndef STRINGCOPY_H
10 #define STRINGCOPY_H
12 #ifdef SCI_NAMESPACE
13 namespace Scintilla {
14 #endif
16 // Safer version of string copy functions like strcpy, wcsncpy, etc.
17 // Instantiate over fixed length strings of both char and wchar_t.
18 // May truncate if source doesn't fit into dest with room for NUL.
20 template <typename T, size_t count>
21 void StringCopy(T (&dest)[count], const T* source) {
22 for (size_t i=0; i<count; i++) {
23 dest[i] = source[i];
24 if (!source[i])
25 break;
27 dest[count-1] = 0;
30 #define ELEMENTS(a) (sizeof(a) / sizeof(a[0]))
32 #ifdef SCI_NAMESPACE
34 #endif
36 #endif