Skip to content

Commit ef7900d

Browse files
author
Colin Robertson
committed
Fix Markdig issues in text
1 parent 9dcfc01 commit ef7900d

23 files changed

Lines changed: 1494 additions & 1433 deletions

docs/text/benefits-of-character-set-portability.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ ms.author: "mblome"
1212
ms.workload: ["cplusplus"]
1313
---
1414
# Benefits of Character Set Portability
15-
You can benefit from using MFC and C run-time portability features even if you do not currently intend to internationalize your application:
16-
17-
- Coding portably makes your code base flexible. You can later move it easily to Unicode or MBCS.
18-
19-
- Using Unicode makes your applications for Windows more efficient. Because Windows uses Unicode, non-Unicode strings passed to and from the operating system must be translated, which incurs overhead.
2015

21-
22-
## See Also
23-
[Unicode and MBCS](../text/unicode-and-mbcs.md)
24-
[Support for Unicode](../text/support-for-unicode.md)
16+
You can benefit from using MFC and C run-time portability features even if you do not currently intend to internationalize your application:
17+
18+
- Coding portably makes your code base flexible. You can later move it easily to Unicode or MBCS.
19+
20+
- Using Unicode makes your applications for Windows more efficient. Because Windows uses Unicode, non-Unicode strings passed to and from the operating system must be translated, which incurs overhead.
21+
22+
23+
## See Also
24+
25+
[Unicode and MBCS](../text/unicode-and-mbcs.md)<br/>
26+
[Support for Unicode](../text/support-for-unicode.md)

docs/text/buffer-overflow.md

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,43 +12,45 @@ ms.author: "mblome"
1212
ms.workload: ["cplusplus"]
1313
---
1414
# Buffer Overflow
15-
Varying character sizes can cause problems when you put characters into a buffer. Consider the following code, which copies characters from a string, `sz`, into a buffer, `rgch`:
16-
17-
```
18-
cb = 0;
19-
while( cb < sizeof( rgch ) )
20-
rgch[ cb++ ] = *sz++;
21-
```
22-
23-
The question is: Was the last byte copied a lead byte? The following does not solve the problem because it can potentially overflow the buffer:
24-
25-
```
26-
cb = 0;
27-
while( cb < sizeof( rgch ) )
28-
{
29-
_mbccpy( rgch + cb, sz );
30-
cb += _mbclen( sz );
31-
sz = _mbsinc( sz );
32-
}
33-
```
34-
35-
The `_mbccpy` call attempts to do the correct thing — copy the full character, whether it is 1 or 2 bytes. But it does not take into account that the last character copied might not fit the buffer if the character is 2 bytes wide. The correct solution is:
36-
37-
```
38-
cb = 0;
39-
while( (cb + _mbclen( sz )) <= sizeof( rgch ) )
40-
{
41-
_mbccpy( rgch + cb, sz );
42-
cb += _mbclen( sz );
43-
sz = _mbsinc( sz );
44-
}
45-
```
46-
47-
This code tests for possible buffer overflow in the loop test, using `_mbclen` to test the size of the current character pointed to by `sz`. By making a call to the `_mbsnbcpy` function, you can replace the code in the **while** loop with a single line of code. For example:
48-
49-
```
50-
_mbsnbcpy( rgch, sz, sizeof( rgch ) );
51-
```
52-
53-
## See Also
54-
[MBCS Programming Tips](../text/mbcs-programming-tips.md)
15+
16+
Varying character sizes can cause problems when you put characters into a buffer. Consider the following code, which copies characters from a string, `sz`, into a buffer, `rgch`:
17+
18+
```cpp
19+
cb = 0;
20+
while( cb < sizeof( rgch ) )
21+
rgch[ cb++ ] = *sz++;
22+
```
23+
24+
The question is: Was the last byte copied a lead byte? The following does not solve the problem because it can potentially overflow the buffer:
25+
26+
```cpp
27+
cb = 0;
28+
while( cb < sizeof( rgch ) )
29+
{
30+
_mbccpy( rgch + cb, sz );
31+
cb += _mbclen( sz );
32+
sz = _mbsinc( sz );
33+
}
34+
```
35+
36+
The `_mbccpy` call attempts to do the correct thing — copy the full character, whether it is 1 or 2 bytes. But it does not take into account that the last character copied might not fit the buffer if the character is 2 bytes wide. The correct solution is:
37+
38+
```cpp
39+
cb = 0;
40+
while( (cb + _mbclen( sz )) <= sizeof( rgch ) )
41+
{
42+
_mbccpy( rgch + cb, sz );
43+
cb += _mbclen( sz );
44+
sz = _mbsinc( sz );
45+
}
46+
```
47+
48+
This code tests for possible buffer overflow in the loop test, using `_mbclen` to test the size of the current character pointed to by `sz`. By making a call to the `_mbsnbcpy` function, you can replace the code in the **while** loop with a single line of code. For example:
49+
50+
```cpp
51+
_mbsnbcpy( rgch, sz, sizeof( rgch ) );
52+
```
53+
54+
## See Also
55+
56+
[MBCS Programming Tips](../text/mbcs-programming-tips.md)

docs/text/byte-indices.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,28 @@ ms.author: "mblome"
1212
ms.workload: ["cplusplus"]
1313
---
1414
# Byte Indices
15-
Use the following tips:
16-
17-
- Working with a bytewise index into a string presents problems similar to those posed by pointer manipulation. Consider this example, which scans a string for a backslash character:
18-
19-
```
20-
while ( rgch[ i ] != '\\' )
21-
i++;
22-
```
23-
24-
This might index a trail byte, not a lead byte, and thus it might not point to a `character`.
25-
26-
- Use the [_mbclen](../c-runtime-library/reference/mbclen-mblen-mblen-l.md) function to solve the preceding problem:
27-
28-
```
29-
while ( rgch[ i ] != '\\' )
30-
i += _mbclen ( rgch + i );
31-
```
32-
33-
This correctly indexes to a lead byte, hence to a `character`. The `_mbclen` function determines the size of a character (1 or 2 bytes).
34-
35-
## See Also
36-
[MBCS Programming Tips](../text/mbcs-programming-tips.md)
37-
[Last Character in a String](../text/last-character-in-a-string.md)
15+
16+
Use the following tips:
17+
18+
- Working with a bytewise index into a string presents problems similar to those posed by pointer manipulation. Consider this example, which scans a string for a backslash character:
19+
20+
```cpp
21+
while ( rgch[ i ] != '\\' )
22+
i++;
23+
```
24+
25+
This might index a trail byte, not a lead byte, and thus it might not point to a `character`.
26+
27+
- Use the [_mbclen](../c-runtime-library/reference/mbclen-mblen-mblen-l.md) function to solve the preceding problem:
28+
29+
```cpp
30+
while ( rgch[ i ] != '\\' )
31+
i += _mbclen ( rgch + i );
32+
```
33+
34+
This correctly indexes to a lead byte, hence to a `character`. The `_mbclen` function determines the size of a character (1 or 2 bytes).
35+
36+
## See Also
37+
38+
[MBCS Programming Tips](../text/mbcs-programming-tips.md)<br/>
39+
[Last Character in a String](../text/last-character-in-a-string.md)

docs/text/character-assignment.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,36 @@ ms.author: "mblome"
1212
ms.workload: ["cplusplus"]
1313
---
1414
# Character Assignment
15-
Consider the following example, in which the **while** loop scans a string, copying all characters except 'X' into another string:
16-
17-
```
18-
while( *sz2 )
19-
{
20-
if( *sz2 != 'X' )
21-
*sz1++ = *sz2++;
22-
else
23-
sz2++;
24-
}
25-
```
26-
27-
The code copies the byte at `sz2` to the location pointed to by `sz1`, then increments `sz1` to receive the next byte. But if the next character in `sz2` is a double-byte character, the assignment to `sz1` copies only the first byte. The following code uses a portable function to copy the character safely and another to increment `sz1` and `sz2` correctly:
28-
29-
```
30-
while( *sz2 )
31-
{
32-
if( *sz2 != 'X' )
33-
{
34-
_mbscpy_s( sz1, 1, sz2 );
35-
sz1 = _mbsinc( sz1 );
36-
sz2 = _mbsinc( sz2 );
37-
}
38-
else
39-
sz2 = _mbsinc( sz2 );
40-
}
41-
```
42-
43-
## See Also
44-
[MBCS Programming Tips](../text/mbcs-programming-tips.md)
45-
[Character Comparison](../text/character-comparison.md)
15+
16+
Consider the following example, in which the **while** loop scans a string, copying all characters except 'X' into another string:
17+
18+
```cpp
19+
while( *sz2 )
20+
{
21+
if( *sz2 != 'X' )
22+
*sz1++ = *sz2++;
23+
else
24+
sz2++;
25+
}
26+
```
27+
28+
The code copies the byte at `sz2` to the location pointed to by `sz1`, then increments `sz1` to receive the next byte. But if the next character in `sz2` is a double-byte character, the assignment to `sz1` copies only the first byte. The following code uses a portable function to copy the character safely and another to increment `sz1` and `sz2` correctly:
29+
30+
```cpp
31+
while( *sz2 )
32+
{
33+
if( *sz2 != 'X' )
34+
{
35+
_mbscpy_s( sz1, 1, sz2 );
36+
sz1 = _mbsinc( sz1 );
37+
sz2 = _mbsinc( sz2 );
38+
}
39+
else
40+
sz2 = _mbsinc( sz2 );
41+
}
42+
```
43+
44+
## See Also
45+
46+
[MBCS Programming Tips](../text/mbcs-programming-tips.md)<br/>
47+
[Character Comparison](../text/character-comparison.md)

docs/text/character-comparison.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ ms.author: "mblome"
1212
ms.workload: ["cplusplus"]
1313
---
1414
# Character Comparison
15-
Use the following tips:
16-
17-
- Comparing a known lead byte with an ASCII character works correctly:
18-
19-
```
20-
if( *sz1 == 'A' )
21-
```
22-
23-
- Comparing two unknown characters requires the use of one of the macros defined in Mbstring.h:
24-
25-
```
26-
if( !_mbccmp( sz1, sz2) )
27-
```
28-
29-
This ensures that both bytes of a double-byte character are compared for equality.
30-
31-
## See Also
32-
[MBCS Programming Tips](../text/mbcs-programming-tips.md)
33-
[Buffer Overflow](../text/buffer-overflow.md)
15+
16+
Use the following tips:
17+
18+
- Comparing a known lead byte with an ASCII character works correctly:
19+
20+
```cpp
21+
if( *sz1 == 'A' )
22+
```
23+
24+
- Comparing two unknown characters requires the use of one of the macros defined in Mbstring.h:
25+
26+
```cpp
27+
if( !_mbccmp( sz1, sz2) )
28+
```
29+
30+
This ensures that both bytes of a double-byte character are compared for equality.
31+
32+
## See Also
33+
34+
[MBCS Programming Tips](../text/mbcs-programming-tips.md)<br/>
35+
[Buffer Overflow](../text/buffer-overflow.md)

docs/text/general-mbcs-programming-advice.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@ ms.author: "mblome"
1313
ms.workload: ["cplusplus"]
1414
---
1515
# General MBCS Programming Advice
16-
Use the following tips:
17-
18-
- For flexibility, use run-time macros such as `_tcschr` and `_tcscpy` when possible. For more information, see [Generic-Text Mappings in Tchar.h](../text/generic-text-mappings-in-tchar-h.md).
19-
20-
- Use the C run-time `_getmbcp` function to get information about the current code page.
21-
22-
- Do not reuse string resources. Depending on the target language, a given string might have a different meaning when translated. For example, "File" on the application's main menu might translate differently from the string "File" in a dialog box. If you need to use more than one string with the same name, use different string IDs for each.
23-
24-
- You might want to find out whether your application is running on an MBCS-enabled operating system. To do so, set a flag at program startup; do not rely on API calls.
25-
26-
- When designing dialog boxes, allow approximately 30% extra space at the end of static text controls for MBCS translation.
27-
28-
- Be careful when selecting fonts for your application, because some fonts are not available on all systems.
29-
30-
- When selecting the font for dialog boxes, use [MS Shell Dlg](/windows/desktop/Intl/using-ms-shell-dlg-and-ms-shell-dlg-2) instead of MS Sans Serif or Helvetica. MS Shell Dlg is replaced with the correct font by the system before creating the dialog box. Using MS Shell Dlg ensures that any changes in the operating system to deal with this font will automatically be available. (MFC replaces MS Shell Dlg with the DEFAULT_GUI_FONT or the System font on Windows 95, Windows 98, and Windows NT 4 because those systems do not handle MS Shell Dlg correctly.)
31-
32-
- When designing your application, decide which strings can be localized. If in doubt, assume that any given string will be localized. As such, do not mix strings that can be localized with those that cannot.
33-
34-
## See Also
35-
[MBCS Programming Tips](../text/mbcs-programming-tips.md)
36-
[Incrementing and Decrementing Pointers](../text/incrementing-and-decrementing-pointers.md)
16+
17+
Use the following tips:
18+
19+
- For flexibility, use run-time macros such as `_tcschr` and `_tcscpy` when possible. For more information, see [Generic-Text Mappings in Tchar.h](../text/generic-text-mappings-in-tchar-h.md).
20+
21+
- Use the C run-time `_getmbcp` function to get information about the current code page.
22+
23+
- Do not reuse string resources. Depending on the target language, a given string might have a different meaning when translated. For example, "File" on the application's main menu might translate differently from the string "File" in a dialog box. If you need to use more than one string with the same name, use different string IDs for each.
24+
25+
- You might want to find out whether your application is running on an MBCS-enabled operating system. To do so, set a flag at program startup; do not rely on API calls.
26+
27+
- When designing dialog boxes, allow approximately 30% extra space at the end of static text controls for MBCS translation.
28+
29+
- Be careful when selecting fonts for your application, because some fonts are not available on all systems.
30+
31+
- When selecting the font for dialog boxes, use [MS Shell Dlg](/windows/desktop/Intl/using-ms-shell-dlg-and-ms-shell-dlg-2) instead of MS Sans Serif or Helvetica. MS Shell Dlg is replaced with the correct font by the system before creating the dialog box. Using MS Shell Dlg ensures that any changes in the operating system to deal with this font will automatically be available. (MFC replaces MS Shell Dlg with the DEFAULT_GUI_FONT or the System font on Windows 95, Windows 98, and Windows NT 4 because those systems do not handle MS Shell Dlg correctly.)
32+
33+
- When designing your application, decide which strings can be localized. If in doubt, assume that any given string will be localized. As such, do not mix strings that can be localized with those that cannot.
34+
35+
## See Also
36+
37+
[MBCS Programming Tips](../text/mbcs-programming-tips.md)<br/>
38+
[Incrementing and Decrementing Pointers](../text/incrementing-and-decrementing-pointers.md)

0 commit comments

Comments
 (0)