Patrice,
This is bc9Basic's REPLACE x WITH y IN z implementation code
$CPP
$ONEXIT "ULEX.EXE $FILE$.CPP TCHARXLATER_VC.TXT"
$ONEXIT "TCLIB.BAT $FILE$"
'==============================================================================
Dim a$
a$ = "I Want To Go Here And Here And Here And Here And Here!"
REPLACE "Here" With "There" In a$
PRINT a$
Pause
'==============================================================================
produces this c++ code.
Remember the process I use with bc9Basic is all code is ansi, but is then run through the ULEX
utility to produce unicode.
// *********************************************************************
// Created with bc9Basic - BASIC To C/C++ Translator (V) 9.2.7.0 (2017/03/31)
// The bc9Basic translator (bc9.exe) was compiled with
// g++ (tdm64-1) 5.1.0
// ----------------------------------------------------------------------
// BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
// Translated for compiling with the
// Microsoft (R) C/C++ Optimizing Compiler
// On MS Windows
// Using TCLib by Fred Harris
// *********************************************************************
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#define _X(y) y
#include <windows.h>
#define x64
#include "TCLib\stdio.h"
#include "TCLib\string.h"
#include "TCLib\stdlib.h"
#include "TCLib\memory.h"
#include "TCLib\malloc.h"
#include "TCLib\math.h"
#include "TCLib\tchar.h"
#include "TCLib\Strings.cpp"
typedef String fstring;
FILE* stdin;
FILE* stdout;
FILE* stderr;
//<---UNICODE AWARE
#define SFMT (const char*)"%s\r\n"
//>---UNICODE AWARE
// NO HEADERS START
#ifndef _WINDOWS_
//<---UNICODE AWARE
typedef _TCHAR *PCHAR, *LPCH, *PCH, *NPSTR, *LPSTR, *PSTR;
typedef unsigned long DWORD, *PDWORD, *LPDWORD;
typedef unsigned int UINT;
//>---UNICODE AWARE
#endif
// NO HEADERS END
// ***************************************************
// Compiler Defines
// ***************************************************
// C++
#if defined( __cplusplus )
#define overloaded
#define C_EXPORT EXTERN_C __declspec(dllexport)
#define C_IMPORT EXTERN_C __declspec(dllimport)
#define BEGIN_EXTERN_C extern _T("C") {
#define END_EXTERN_C }
#else
#define C_EXPORT __declspec(dllexport)
#define C_IMPORT __declspec(dllimport)
#endif
// Microsoft VC++
#ifndef DECLSPEC_UUID
#if (_MSC_VER >= 1100) && defined ( __cplusplus )
#define DECLSPEC_UUID(x) __declspec(uuid(x))
#else
#define DECLSPEC_UUID(x)
#endif
#endif
// ***************************************************
// Compiler Defines
// ***************************************************
#ifndef __cplusplus
#error A C++ compiler is required
#endif
// *************************************************
// User's GLOBAL ENUM blocks
// *************************************************
// *************************************************
// System Defined Constants
// *************************************************
typedef const _TCHAR* ccptr;
#define CCPTR const _TCHAR*
#define cfree free
//<---UNICODE AWARE
typedef char _char;
#define _strlen strlen
//>---UNICODE AWARE
#define EQU ==
#define NOT_USED(x) if(x);
#define CTLHNDL(id) GetDlgItem(hWnd,id)
_TCHAR *g_cptr_; // dummy var for not used returns
unsigned int g_dum1_; // dummy var for not used returns
int g_dum_int; // dummy int var for not used returns
#define cSizeOfDefaultString 2048
// *************************************************
// User Defined Constants
// *************************************************
// *************************************************
// Standard Prototypes
// *************************************************
_TCHAR* BCX_TmpStr(size_t, size_t = 0, int = 1);
_TCHAR* replace (const _TCHAR*, const _TCHAR*, const _TCHAR*);
_TCHAR *_tcsstr_(_TCHAR*, _TCHAR*);
void Pause (void);
// *************************************************
// System Variables
// *************************************************
// *************************************************
// User Defined Types, Unions and Classes
// *************************************************
// *************************************************
// User Global Variables
// *************************************************
static _TCHAR a[cSizeOfDefaultString];
// *************************************************
// User Global Initialized Arrays
// *************************************************
// *************************************************
// Runtime Functions
// *************************************************
#ifndef BCXTmpStrSize
#define BCXTmpStrSize 2048
#endif
_TCHAR *BCX_TmpStr (size_t Bites, size_t iPad, int iAlloc)
{
static int StrCnt;
static _TCHAR *StrFunc[BCXTmpStrSize];
StrCnt = (StrCnt + 1) & (BCXTmpStrSize - 1);
if(StrFunc[StrCnt]) {
free (StrFunc[StrCnt]);
StrFunc[StrCnt] = NULL;
}
#if defined BCX_MAX_VAR_SIZE
if(Bites * sizeof(_TCHAR) > BCX_MAX_VAR_SIZE)
{
_tprintf(_T("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n"), (int)(Bites * sizeof(_TCHAR)), BCX_MAX_VAR_SIZE);
abort();
}
#endif
if(iAlloc) StrFunc[StrCnt] = (_TCHAR*)calloc(Bites + iPad + 1, sizeof(_TCHAR));
return StrFunc[StrCnt];
}
_TCHAR *replace (const _TCHAR *src, const _TCHAR *pat, const _TCHAR *rep)
{
size_t patsz, repsz, tmpsz, delta;
_TCHAR *strtmp, *p, *q, *r;
if (!pat || !*pat)
{
strtmp = BCX_TmpStr(_tcslen(src), 1, 1);
if (!strtmp) return NULL;
return _tcscpy(strtmp, src);
}
repsz = _tcslen(rep);
patsz = _tcslen(pat);
for (tmpsz = 0, p = (_TCHAR*)src; (q = _tcsstr_(p, (_TCHAR*)pat)) != 0; p = q + patsz)
tmpsz += (size_t) (q - p) + repsz;
tmpsz += _tcslen(p);
strtmp = BCX_TmpStr(tmpsz, 1, 1);
if (!strtmp) return NULL;
for (r = strtmp, p = (_TCHAR*)src; (q = _tcsstr_(p, (_TCHAR*)pat)) != 0; p = q + patsz)
{
delta = (size_t) (q - p);
wmemcpy(r, p, delta);
r += delta;
_tcscpy(r, rep);
r += repsz;
}
_tcscpy(r, p);
return strtmp;
}
void Pause(void)
{
_tprintf(_T("\n%ls\n"), _T("Press any key to continue..."));
_getwch();
}
_TCHAR *_tcsstr_(_TCHAR *String, _TCHAR *Pattern)
{
int mi = -1;
while(Pattern[++mi])
{
if(String[mi] == 0) return 0;
if(String[mi] != Pattern[mi])
{
String++;
mi = -1;
}
}
return String;
}
// *************************************************
// User Subs, Functions and Class Methods
// *************************************************
// *************************************************
// Main Program
// *************************************************
int _tmain(int argc, _TCHAR *argv[])
{
_tcscpy(a, _T("I Want To Go Here And Here And Here And Here And Here!"));
_tcscpy(a, replace(a, _T("Here"), _T("There")));
_tprintf(_T("%ls\n"), a);
Pause();
return 0; /* End of _tmain program */
}
James