MCPcopy Create free account
hub / github.com/AppleWin/AppleWin / TextConvertTabsToSpaces

Function TextConvertTabsToSpaces

source/Debugger/Debugger_Parser.cpp:870–936  ·  view source on GitHub ↗

===========================================================================

Source from the content-addressed store, hash-verified

868
869//===========================================================================
870void TextConvertTabsToSpaces( char *pDeTabified_, LPCTSTR pText, const int nDstSize, int nTabStop )
871{
872 int TAB_SPACING = 8;
873 int TAB_SPACING_1 = 16;
874 int TAB_SPACING_2 = 21;
875
876 if (nTabStop)
877 TAB_SPACING = nTabStop;
878
879 LPCTSTR pSrc = pText;
880 LPTSTR pDst = pDeTabified_;
881
882 int nTab = 0; // gap left to next tab
883 int nGap = 0; // actual gap
884 int nCur = 0; // current cursor position
885 while (pSrc && *pSrc && (nCur < nDstSize))
886 {
887 if (*pSrc == CHAR_TAB)
888 {
889 if (nTabStop)
890 {
891 nTab = nCur % TAB_SPACING;
892 nGap = (TAB_SPACING - nTab);
893 }
894 else
895 {
896 if (nCur <= TAB_SPACING_1)
897 {
898 nGap = (TAB_SPACING_1 - nCur);
899 }
900 else
901 if (nCur <= TAB_SPACING_2)
902 {
903 nGap = (TAB_SPACING_2 - nCur);
904 }
905 else
906 {
907 nTab = nCur % TAB_SPACING;
908 nGap = (TAB_SPACING - nTab);
909 }
910 }
911
912
913 if ((nCur + nGap) >= nDstSize)
914 break;
915
916 for ( int iSpc = 0; iSpc < nGap; iSpc++ )
917 {
918 *pDst++ = CHAR_SPACE;
919 }
920 nCur += nGap;
921 }
922 else
923 if ((*pSrc == CHAR_LF) || (*pSrc == CHAR_CR))
924 {
925 *pDst++ = 0; // *pSrc;
926 nCur++;
927 }

Callers 2

DrawSourceLineFunction · 0.85
CmdProfileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected