updated gensub to support the occurrence number (the third argument)
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		
							
								
								
									
										23
									
								
								t/h-002.hawk
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								t/h-002.hawk
									
									
									
									
									
								
							| @ -196,6 +196,29 @@ function main() | ||||
| 		tap_ensure (z, @r"x\&ax", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 	} | ||||
|  | ||||
| 	## gensub | ||||
| 	{ | ||||
| 		@local x; | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", "g", "the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, "the tiger-tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", 'G', "the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, "the tiger-tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", 'G', @b"the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, @b"the tiger-tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 		tap_ensure (hawk::typename(x), "mbs", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", 1, "the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, "the tiger-tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", 2, "the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, "the tiger pounces on the dog-dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
|  | ||||
| 		## 0 as the third argument is same as not passing "g"/"G" or a positive occurrence number. | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", 0, "the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, "the tiger-tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", "", "the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, "the tiger-tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 		x = gensub(/(tiger|dog)/, "\\1-\\1", 10, "the tiger pounces on the dog"); | ||||
| 		tap_ensure (x, "the tiger pounces on the dog", @SCRIPTNAME, @SCRIPTLINE); | ||||
| 	} | ||||
|  | ||||
| 	{ | ||||
| 		@local pi, e, tmp; | ||||
|  | ||||
| @ -194,7 +194,7 @@ int main(int argc, char* argv[]) | ||||
|  | ||||
| 	malloc_time = (double)(end_time - start_time) / CLOCKS_PER_SEC - free_time; | ||||
|  | ||||
| 	printf("Performed %d interleaved malloc/free operations\n", num_iterations); | ||||
| 	printf("Performed %lu interleaved malloc/free operations\n", (unsigned long)num_iterations); | ||||
| 	printf("Total malloc time (estimated): %.6f seconds\n", malloc_time); | ||||
| 	printf("Total free time              : %.6f seconds\n", free_time); | ||||
| 	printf("Average time per operation   : %.9f seconds\n", (malloc_time + free_time) / num_iterations); | ||||
|  | ||||
		Reference in New Issue
	
	Block a user