5 InsSpacePos(PCWSTR szInsStr
, const int nPos
)
12 pszDestStr
= (PWSTR
)HeapAlloc(GetProcessHeap(), 0, MAX_SAMPLES_STR_SIZE
* sizeof(WCHAR
));
13 if (pszDestStr
== NULL
)
16 wcscpy(pszDestStr
, szInsStr
);
18 nStrSize
= wcslen(szInsStr
);
20 for (nStrCnt
= 0; nStrCnt
< nStrSize
; nStrCnt
++)
22 if (nStrCnt
== nStrSize
- nPos
)
24 pszDestStr
[nDestStrCnt
] = L
' ';
28 pszDestStr
[nDestStrCnt
] = szInsStr
[nStrCnt
];
32 pszDestStr
[nDestStrCnt
] = L
'\0';
37 /* Insert the spaces by format string separated by ';' */
39 InsSpacesFmt(PCWSTR szSourceStr
, PCWSTR szFmtStr
)
50 pszDestStr
= (PWSTR
)HeapAlloc(GetProcessHeap(), 0, 255 * sizeof(WCHAR
));
51 if (pszDestStr
== NULL
)
54 wcscpy(pszDestStr
, szSourceStr
);
56 /* If format is clean return source string */
60 /* Search for all format values */
61 for (nFmtCount
= 0; nFmtCount
<= wcslen(szFmtStr
); nFmtCount
++)
63 if (szFmtStr
[nFmtCount
] == L
';' || szFmtStr
[nFmtCount
] == L
'\0')
65 if (_wtoi(szFmtVal
) == 0 && !wasNul
)
71 /* If was 0, repeat spaces */
74 nSpaceOffset
+= nLastVal
;
78 nSpaceOffset
+= _wtoi(szFmtVal
);
81 szFmtVal
[nValCount
] = L
'\0';
84 /* Insert space to finded position plus all pos before */
85 pszTempStr
= InsSpacePos(pszDestStr
, nSpaceOffset
);
86 wcscpy(pszDestStr
,pszTempStr
);
87 HeapFree(GetProcessHeap(), 0, pszTempStr
);
89 /* Num of spaces total increment */
93 nLastVal
= _wtoi(szFmtVal
);
98 szFmtVal
[nValCount
++] = szFmtStr
[nFmtCount
];
102 /* Create spaces for rest part of string */
103 if (wasNul
&& nLastVal
!= 0)
105 for (nFmtCount
= nSpaceOffset
+ nLastVal
; nFmtCount
< wcslen(pszDestStr
); nFmtCount
+= nLastVal
+ 1)
107 pszTempStr
= InsSpacePos(pszDestStr
, nFmtCount
);
108 wcscpy(pszDestStr
, pszTempStr
);
109 HeapFree(GetProcessHeap(), 0, pszTempStr
);
116 /* Replace given template in source string with string to replace and return received string */
118 ReplaceSubStr(PCWSTR szSourceStr
,
119 PCWSTR szStrToReplace
,
128 szDestStr
= (PWSTR
)HeapAlloc(GetProcessHeap(), 0, MAX_SAMPLES_STR_SIZE
* sizeof(WCHAR
));
129 if (szDestStr
== NULL
)
135 wcscpy(szDestStr
, L
"");
137 while (nFirstCharCnt
< wcslen(szSourceStr
))
139 if (szSourceStr
[nFirstCharCnt
] == szTempl
[0])
142 for (nCharCnt
= nFirstCharCnt
; nCharCnt
< nFirstCharCnt
+ wcslen(szTempl
); nCharCnt
++)
144 if (szSourceStr
[nCharCnt
] == szTempl
[nSubStrCnt
])
153 if (wcslen(szTempl
) == nSubStrCnt
)
155 wcscat(szDestStr
, szStrToReplace
);
156 nDestStrCnt
= wcslen(szDestStr
);
157 nFirstCharCnt
+= wcslen(szTempl
) - 1;
164 szDestStr
[nDestStrCnt
++] = szSourceStr
[nFirstCharCnt
];
165 szDestStr
[nDestStrCnt
] = L
'\0';