Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The VFP functions At() and AtC() do not work properly #365

Closed
Karl1155 opened this issue Apr 19, 2020 · 1 comment
Closed

The VFP functions At() and AtC() do not work properly #365

Karl1155 opened this issue Apr 19, 2020 · 1 comment
Assignees

Comments

@Karl1155
Copy link

In both funcs it´s necessary to:

  • add 1 to the search result
  • and exit the loop as soon the search result is 0
FUNCTION Start() AS VOID
	
	? "AtC()" 
	? AtC_Current("Bu", "abucabucbba", 2 ) //  shows 1 instead of 6 
	? AtC_Current("Bu", "abucabucbba", 1 ) //  shows 1 instead of 2		
	? AtC_Current("Bu", "abucabucbba", 12 ) // shows 1 instead of 0   
	
	?
	? AtC_Fix("Bu", "abucabucbba", 2 ) 	  // ok, 6
	? AtC_Fix("Bu", "abucabucbba", 1 ) 	  // ok, 2	
	? AtC_Fix("Bu", "abucabucbba", 12 )  // ok, 0 	
	?

	? "At()" 
	? At_Current("b", "abucabucbba", 3 ) //  shows 1 instead of 9 
	? At_Current("bu", "abucabucbba", 1 ) //  shows 1 instead of 2		
	? At_Current("bu", "abucabucbba", 12 ) // shows 1 instead of 0 
	
	?
	? At_Fix("b", "abucabucbba", 3 )	  // ok, 9 
	? At_Fix("bu", "abucabucbba", 1 ) 	  // ok, 2	
	? At_Fix("bu", "abucabucbba", 12 )  // ok , 0	

	RETURN   


// --------- XSharpPublic/Runtime/XSharp.VFP/ToDo-A.prg  ----------

FUNCTION At_Current(cSearchExpression AS STRING, cExpressionSearched AS STRING, nOccurrence := 1 AS DWORD) AS DWORD
	LOCAL position := 0 AS DWORD
	IF ( cExpressionSearched != NULL .AND. cSearchExpression != NULL )
		IF cExpressionSearched:Length != 0 .AND. cSearchExpression:Length != 0
			DO WHILE nOccurrence  > 0
				position := (DWORD) cExpressionSearched:IndexOf(cSearchExpression, (INT) position,StringComparison.Ordinal) 
				nOccurrence -= 1
			ENDDO
		END IF
	ENDIF
	RETURN position	
	
FUNCTION AtC_Current(cSearchExpression AS STRING, cExpressionSearched AS STRING, nOccurrence := 1 AS DWORD) AS DWORD
	LOCAL position := 0 AS DWORD
	IF ( cExpressionSearched != NULL .AND. cSearchExpression != NULL )
		IF cExpressionSearched:Length != 0 .AND. cSearchExpression:Length != 0
			DO WHILE nOccurrence  > 0
				position := (DWORD) cExpressionSearched:IndexOf(cSearchExpression, (INT) position,StringComparison.OrdinalIgnoreCase) 
				nOccurrence -= 1
			ENDDO
		END IF
	ENDIF
	RETURN position	 
	
// ------------------  Fixes ------------------------------------	
	
FUNCTION At_Fix(cSearchExpression AS STRING, cExpressionSearched AS STRING, nOccurrence := 1 AS DWORD) AS DWORD
	LOCAL position := 0 AS DWORD
	IF ( cExpressionSearched != NULL .AND. cSearchExpression != NULL )
		IF cExpressionSearched:Length != 0 .AND. cSearchExpression:Length != 0
			DO WHILE nOccurrence  > 0
				IF ( position := (DWORD) cExpressionSearched:IndexOf(cSearchExpression, (INT) position,StringComparison.Ordinal) + 1) == 0
					EXIT
				ENDIF	
				nOccurrence -= 1
			ENDDO
		END IF
	ENDIF
	RETURN position	
	
FUNCTION AtC_Fix(cSearchExpression AS STRING, cExpressionSearched AS STRING, nOccurrence := 1 AS DWORD) AS DWORD
	LOCAL position := 0 AS DWORD
	IF ( cExpressionSearched != NULL .AND. cSearchExpression != NULL )
		IF cExpressionSearched:Length != 0 .AND. cSearchExpression:Length != 0
			DO WHILE nOccurrence  > 0
				IF ( position := (DWORD) cExpressionSearched:IndexOf(cSearchExpression, (INT) position,StringComparison.OrdinalIgnoreCase) + 1) == 0
					EXIT
				ENDIF				  
				nOccurrence -= 1
			ENDDO
		END IF
	ENDIF
	RETURN position

Karl-Heinz

@cpyrgas
Copy link

cpyrgas commented Apr 27, 2020

Thanks Karl-Heinz and sorry for the delay getting back to you. I have made the changes and also added a few tests. You cannot see the changes yet because my repository is messed up right now, but they are done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants