WeixiangYan/CodeTransOcean huggingface dataset:
Task: Text between



C#: using System;

namespace TextBetween {
    class Program {
        static string TextBetween(string source, string beg, string end) {
            int startIndex;

            if (beg == "start") {
                startIndex = 0;
            }
            else {
                startIndex = source.IndexOf(beg);
                if (startIndex < 0) {
                    return "";
                }
                startIndex += beg.Length;
            }

            int endIndex = source.IndexOf(end, startIndex);
            if (endIndex < 0 || end == "end") {
                return source.Substring(startIndex);
            }
            return source.Substring(startIndex, endIndex - startIndex);
        }

        static void Print(string s, string b, string e) {
            Console.WriteLine("text: '{0}'", s);
            Console.WriteLine("start: '{0}'", b);
            Console.WriteLine("end: '{0}'", e);
            Console.WriteLine("result: '{0}'", TextBetween(s, b, e));
            Console.WriteLine();
        }

        static void Main(string[] args) {
            Print("Hello Rosetta Code world", "Hello ", " world");
            Print("Hello Rosetta Code world", "start", " world");
            Print("Hello Rosetta Code world", "Hello ", "end");
            Print("</div><div style=\"chinese\">你好嗎</div>", "<div style=\"chinese\">", "</div>");
            Print("<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">", "<text>", "<table>");
            Print("<table style=\"myTable\"><tr><td>hello world</td></tr></table>", "<table>", "</table>");
            Print("The quick brown fox jumps over the lazy other fox", "quick ", " fox");
            Print("One fish two fish red fish blue fish", "fish ", " red");
            Print("FooBarBazFooBuxQuux", "Foo", "Foo");
        }
    }
}





Python: 
from sys import argv






def textBetween( thisText, startString, endString ):
    try:
    	if startString is 'start':
    		startIndex = 0
    	else:
    		startIndex = thisText.index( startString ) 
    	
    	if not (startIndex >= 0):
    		return 'Start delimiter not found'
    	else:
        	if startString is not 'start':
        		startIndex = startIndex + len( startString )
        
        returnText = thisText[startIndex:]


    	if endString is 'end':
    		return returnText
    	else:
    		endIndex = returnText.index( endString )

    	if not (endIndex >= 0):
    		return 'End delimiter not found'
    	else:
        	returnText = returnText[:endIndex]

        return returnText
    except ValueError:
        return "Value error"

script, first, second, third = argv

thisText = first
startString = second
endString = third

print textBetween( thisText, startString, endString )
Task: Text between




Go: package main

import (
    "fmt"
    "strings"
)

func textBetween(str, start, end string) string {
    if str == "" || start == "" || end == "" {
        return str
    }
    s := 0
    if start != "start" {
        s = strings.Index(str, start)
    }
    if s == -1 {
        return ""
    }
    si := 0
    if start != "start" {
        si = s + len(start)
    }
    e := len(str)
    if end != "end" {
        e = strings.Index(str[si:], end)
        if e == -1 {
            return str[si:]
        }
        e += si
    }
    return str[si:e]
}

func main() {
    texts := [9]string{
        "Hello Rosetta Code world",
        "Hello Rosetta Code world",
        "Hello Rosetta Code world",
        "</div><div style=\"chinese\">你好嗎</div>",
        "<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">",
        "<table style=\"myTable\"><tr><td>hello world</td></tr></table>",
        "The quick brown fox jumps over the lazy other fox",
        "One fish two fish red fish blue fish",
        "FooBarBazFooBuxQuux",
    }
    starts:= [9]string{
        "Hello ", "start", "Hello ", "<div style=\"chinese\">",
        "<text>", "<table>", "quick ", "fish ", "Foo",
    }
    ends := [9]string{
        " world", " world", "end", "</div>", "<table>",
        "</table>", " fox", " red", "Foo",
    }
    for i, text := range texts {
        fmt.Printf("Text: \"%s\"\n", text)
        fmt.Printf("Start delimiter: \"%s\"\n", starts[i])
        fmt.Printf("End delimiter: \"%s\"\n", ends[i])
        b := textBetween(text, starts[i], ends[i])
        fmt.Printf("Output: \"%s\"\n\n", b)
    }
}


Java: public class textBetween
{
    
    static String textBetween(String thisText, String startString, String endString)
    {
    	String returnText = "";
    	int startIndex = 0;
    	int endIndex = 0;
    	
    	if (startString.equals("start"))
    	{
    		startIndex = 0;
    	} else {
	    	startIndex = thisText.indexOf(startString);
	    	
	    	if (startIndex < 0) 
	        {
	        	return "";	        	
	        } else {
	        	startIndex = startIndex + startString.length();
	        }
    	}
        
    	if (endString.equals("end"))
    	{
    		endIndex = thisText.length();
    	} else {
    		endIndex = thisText.indexOf(endString);
            
            if (endIndex <= 0) 
            {
            	return "";
            } else {

            }	
    	}
    	
    	returnText = thisText.substring(startIndex,endIndex);
    	
    	return returnText;
    } 

    
    public static void main(String[] args)
    {
    	String thisText = args[0];
    	String startDelimiter = args[1];
    	String endDelimiter = args[2];
    	
    	String returnText = "";
    	returnText = textBetween(thisText, startDelimiter, endDelimiter);
    	
        System.out.println(returnText);

    } 
    
}
Task: Text between




Go: package main

import (
    "fmt"
    "strings"
)

func textBetween(str, start, end string) string {
    if str == "" || start == "" || end == "" {
        return str
    }
    s := 0
    if start != "start" {
        s = strings.Index(str, start)
    }
    if s == -1 {
        return ""
    }
    si := 0
    if start != "start" {
        si = s + len(start)
    }
    e := len(str)
    if end != "end" {
        e = strings.Index(str[si:], end)
        if e == -1 {
            return str[si:]
        }
        e += si
    }
    return str[si:e]
}

func main() {
    texts := [9]string{
        "Hello Rosetta Code world",
        "Hello Rosetta Code world",
        "Hello Rosetta Code world",
        "</div><div style=\"chinese\">你好嗎</div>",
        "<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">",
        "<table style=\"myTable\"><tr><td>hello world</td></tr></table>",
        "The quick brown fox jumps over the lazy other fox",
        "One fish two fish red fish blue fish",
        "FooBarBazFooBuxQuux",
    }
    starts:= [9]string{
        "Hello ", "start", "Hello ", "<div style=\"chinese\">",
        "<text>", "<table>", "quick ", "fish ", "Foo",
    }
    ends := [9]string{
        " world", " world", "end", "</div>", "<table>",
        "</table>", " fox", " red", "Foo",
    }
    for i, text := range texts {
        fmt.Printf("Text: \"%s\"\n", text)
        fmt.Printf("Start delimiter: \"%s\"\n", starts[i])
        fmt.Printf("End delimiter: \"%s\"\n", ends[i])
        b := textBetween(text, starts[i], ends[i])
        fmt.Printf("Output: \"%s\"\n\n", b)
    }
}




Python: 
from sys import argv






def textBetween( thisText, startString, endString ):
    try:
    	if startString is 'start':
    		startIndex = 0
    	else:
    		startIndex = thisText.index( startString ) 
    	
    	if not (startIndex >= 0):
    		return 'Start delimiter not found'
    	else:
        	if startString is not 'start':
        		startIndex = startIndex + len( startString )
        
        returnText = thisText[startIndex:]


    	if endString is 'end':
    		return returnText
    	else:
    		endIndex = returnText.index( endString )

    	if not (endIndex >= 0):
    		return 'End delimiter not found'
    	else:
        	returnText = returnText[:endIndex]

        return returnText
    except ValueError:
        return "Value error"

script, first, second, third = argv

thisText = first
startString = second
endString = third

print textBetween( thisText, startString, endString )
Task: Text between

C: 
char* textBetween(char* thisText, char* startText, char* endText, char* returnText)
{
	

    char* startPointer = NULL;
    int stringLength = 0;

    char* endPointer = NULL;
    int endLength = 0;

	if (strstr(startText, "start") != NULL)
	{
		
		startPointer = thisText;
	} else {
		startPointer = strstr(thisText, startText);

    	if (startPointer != NULL)
	    {
        	startPointer = startPointer + strlen(startText);
        }
	} 
    
    if (startPointer != NULL)
    {

		if (strstr(endText, "end") != NULL)
		{
			
			endPointer = thisText;
			endLength = 0;
		} else {
			endPointer = strstr(startPointer, endText);
			endLength = (int)strlen(endPointer);
		} 

        stringLength = strlen(startPointer) - endLength;
        
        if (stringLength == 0)
        {
		    returnText = "";
		    startPointer = NULL;
        } else {
	        
    	    strncpy(returnText,startPointer, stringLength);
	        returnText[stringLength++] = '\0';
		}
        
    } else {
	    
	    returnText = "";
	    
    } 
    
    return startPointer;
} 


C++: #include <iostream>

std::ostream& operator<<(std::ostream& out, const std::string& str) {
    return out << str.c_str();
}

std::string textBetween(const std::string& source, const std::string& beg, const std::string& end) {
    size_t startIndex;
    if (beg == "start") {
        startIndex = 0;
    } else {
        startIndex = source.find(beg);
        if (startIndex == std::string::npos) {
            return "";
        }
        startIndex += beg.length();
    }

    size_t endIndex = source.find(end, startIndex);
    if (endIndex == std::string::npos || end == "end") {
        return source.substr(startIndex);
    }

    return source.substr(startIndex, endIndex - startIndex);
}

void print(const std::string& source, const std::string& beg, const std::string& end) {
    using namespace std;
    cout << "text: '" << source << "'\n";
    cout << "start: '" << beg << "'\n";
    cout << "end: '" << end << "'\n";
    cout << "result: '" << textBetween(source, beg, end) << "'\n";
    cout << '\n';
}

int main() {
    print("Hello Rosetta Code world", "Hello ", " world");
    print("Hello Rosetta Code world", "start", " world");
    print("Hello Rosetta Code world", "Hello ", "end");
    print("<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">", "<text>", "<table>");
    print("<table style=\"myTable\"><tr><td>hello world</td></tr></table>", "<table>", "</table>");
    print("The quick brown fox jumps over the lazy other fox", "quick ", " fox");
    print("One fish two fish red fish blue fish", "fish ", " red");
    print("FooBarBazFooBuxQuux", "Foo", "Foo");

    return 0;
}
Task: Text between

C: 
char* textBetween(char* thisText, char* startText, char* endText, char* returnText)
{
	

    char* startPointer = NULL;
    int stringLength = 0;

    char* endPointer = NULL;
    int endLength = 0;

	if (strstr(startText, "start") != NULL)
	{
		
		startPointer = thisText;
	} else {
		startPointer = strstr(thisText, startText);

    	if (startPointer != NULL)
	    {
        	startPointer = startPointer + strlen(startText);
        }
	} 
    
    if (startPointer != NULL)
    {

		if (strstr(endText, "end") != NULL)
		{
			
			endPointer = thisText;
			endLength = 0;
		} else {
			endPointer = strstr(startPointer, endText);
			endLength = (int)strlen(endPointer);
		} 

        stringLength = strlen(startPointer) - endLength;
        
        if (stringLength == 0)
        {
		    returnText = "";
		    startPointer = NULL;
        } else {
	        
    	    strncpy(returnText,startPointer, stringLength);
	        returnText[stringLength++] = '\0';
		}
        
    } else {
	    
	    returnText = "";
	    
    } 
    
    return startPointer;
} 




Go: package main

import (
    "fmt"
    "strings"
)

func textBetween(str, start, end string) string {
    if str == "" || start == "" || end == "" {
        return str
    }
    s := 0
    if start != "start" {
        s = strings.Index(str, start)
    }
    if s == -1 {
        return ""
    }
    si := 0
    if start != "start" {
        si = s + len(start)
    }
    e := len(str)
    if end != "end" {
        e = strings.Index(str[si:], end)
        if e == -1 {
            return str[si:]
        }
        e += si
    }
    return str[si:e]
}

func main() {
    texts := [9]string{
        "Hello Rosetta Code world",
        "Hello Rosetta Code world",
        "Hello Rosetta Code world",
        "</div><div style=\"chinese\">你好嗎</div>",
        "<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">",
        "<table style=\"myTable\"><tr><td>hello world</td></tr></table>",
        "The quick brown fox jumps over the lazy other fox",
        "One fish two fish red fish blue fish",
        "FooBarBazFooBuxQuux",
    }
    starts:= [9]string{
        "Hello ", "start", "Hello ", "<div style=\"chinese\">",
        "<text>", "<table>", "quick ", "fish ", "Foo",
    }
    ends := [9]string{
        " world", " world", "end", "</div>", "<table>",
        "</table>", " fox", " red", "Foo",
    }
    for i, text := range texts {
        fmt.Printf("Text: \"%s\"\n", text)
        fmt.Printf("Start delimiter: \"%s\"\n", starts[i])
        fmt.Printf("End delimiter: \"%s\"\n", ends[i])
        b := textBetween(text, starts[i], ends[i])
        fmt.Printf("Output: \"%s\"\n\n", b)
    }
}
Task: Text between

C: 
char* textBetween(char* thisText, char* startText, char* endText, char* returnText)
{
	

    char* startPointer = NULL;
    int stringLength = 0;

    char* endPointer = NULL;
    int endLength = 0;

	if (strstr(startText, "start") != NULL)
	{
		
		startPointer = thisText;
	} else {
		startPointer = strstr(thisText, startText);

    	if (startPointer != NULL)
	    {
        	startPointer = startPointer + strlen(startText);
        }
	} 
    
    if (startPointer != NULL)
    {

		if (strstr(endText, "end") != NULL)
		{
			
			endPointer = thisText;
			endLength = 0;
		} else {
			endPointer = strstr(startPointer, endText);
			endLength = (int)strlen(endPointer);
		} 

        stringLength = strlen(startPointer) - endLength;
        
        if (stringLength == 0)
        {
		    returnText = "";
		    startPointer = NULL;
        } else {
	        
    	    strncpy(returnText,startPointer, stringLength);
	        returnText[stringLength++] = '\0';
		}
        
    } else {
	    
	    returnText = "";
	    
    } 
    
    return startPointer;
} 





Java: public class textBetween
{
    
    static String textBetween(String thisText, String startString, String endString)
    {
    	String returnText = "";
    	int startIndex = 0;
    	int endIndex = 0;
    	
    	if (startString.equals("start"))
    	{
    		startIndex = 0;
    	} else {
	    	startIndex = thisText.indexOf(startString);
	    	
	    	if (startIndex < 0) 
	        {
	        	return "";	        	
	        } else {
	        	startIndex = startIndex + startString.length();
	        }
    	}
        
    	if (endString.equals("end"))
    	{
    		endIndex = thisText.length();
    	} else {
    		endIndex = thisText.indexOf(endString);
            
            if (endIndex <= 0) 
            {
            	return "";
            } else {

            }	
    	}
    	
    	returnText = thisText.substring(startIndex,endIndex);
    	
    	return returnText;
    } 

    
    public static void main(String[] args)
    {
    	String thisText = args[0];
    	String startDelimiter = args[1];
    	String endDelimiter = args[2];
    	
    	String returnText = "";
    	returnText = textBetween(thisText, startDelimiter, endDelimiter);
    	
        System.out.println(returnText);

    } 
    
}
Task: Text between



C#: using System;

namespace TextBetween {
    class Program {
        static string TextBetween(string source, string beg, string end) {
            int startIndex;

            if (beg == "start") {
                startIndex = 0;
            }
            else {
                startIndex = source.IndexOf(beg);
                if (startIndex < 0) {
                    return "";
                }
                startIndex += beg.Length;
            }

            int endIndex = source.IndexOf(end, startIndex);
            if (endIndex < 0 || end == "end") {
                return source.Substring(startIndex);
            }
            return source.Substring(startIndex, endIndex - startIndex);
        }

        static void Print(string s, string b, string e) {
            Console.WriteLine("text: '{0}'", s);
            Console.WriteLine("start: '{0}'", b);
            Console.WriteLine("end: '{0}'", e);
            Console.WriteLine("result: '{0}'", TextBetween(s, b, e));
            Console.WriteLine();
        }

        static void Main(string[] args) {
            Print("Hello Rosetta Code world", "Hello ", " world");
            Print("Hello Rosetta Code world", "start", " world");
            Print("Hello Rosetta Code world", "Hello ", "end");
            Print("</div><div style=\"chinese\">你好嗎</div>", "<div style=\"chinese\">", "</div>");
            Print("<text>Hello <span>Rosetta Code</span> world</text><table style=\"myTable\">", "<text>", "<table>");
            Print("<table style=\"myTable\"><tr><td>hello world</td></tr></table>", "<table>", "</table>");
            Print("The quick brown fox jumps over the lazy other fox", "quick ", " fox");
            Print("One fish two fish red fish blue fish", "fish ", " red");
            Print("FooBarBazFooBuxQuux", "Foo", "Foo");
        }
    }
}



Java: public class textBetween
{
    
    static String textBetween(String thisText, String startString, String endString)
    {
    	String returnText = "";
    	int startIndex = 0;
    	int endIndex = 0;
    	
    	if (startString.equals("start"))
    	{
    		startIndex = 0;
    	} else {
	    	startIndex = thisText.indexOf(startString);
	    	
	    	if (startIndex < 0) 
	        {
	        	return "";	        	
	        } else {
	        	startIndex = startIndex + startString.length();
	        }
    	}
        
    	if (endString.equals("end"))
    	{
    		endIndex = thisText.length();
    	} else {
    		endIndex = thisText.indexOf(endString);
            
            if (endIndex <= 0) 
            {
            	return "";
            } else {

            }	
    	}
    	
    	returnText = thisText.substring(startIndex,endIndex);
    	
    	return returnText;
    } 

    
    public static void main(String[] args)
    {
    	String thisText = args[0];
    	String startDelimiter = args[1];
    	String endDelimiter = args[2];
    	
    	String returnText = "";
    	returnText = textBetween(thisText, startDelimiter, endDelimiter);
    	
        System.out.println(returnText);

    } 
    
}
Task: Text between





Java: public class textBetween
{
    
    static String textBetween(String thisText, String startString, String endString)
    {
    	String returnText = "";
    	int startIndex = 0;
    	int endIndex = 0;
    	
    	if (startString.equals("start"))
    	{
    		startIndex = 0;
    	} else {
	    	startIndex = thisText.indexOf(startString);
	    	
	    	if (startIndex < 0) 
	        {
	        	return "";	        	
	        } else {
	        	startIndex = startIndex + startString.length();
	        }
    	}
        
    	if (endString.equals("end"))
    	{
    		endIndex = thisText.length();
    	} else {
    		endIndex = thisText.indexOf(endString);
            
            if (endIndex <= 0) 
            {
            	return "";
            } else {

            }	
    	}
    	
    	returnText = thisText.substring(startIndex,endIndex);
    	
    	return returnText;
    } 

    
    public static void main(String[] args)
    {
    	String thisText = args[0];
    	String startDelimiter = args[1];
    	String endDelimiter = args[2];
    	
    	String returnText = "";
    	returnText = textBetween(thisText, startDelimiter, endDelimiter);
    	
        System.out.println(returnText);

    } 
    
} 



Python: 
from sys import argv






def textBetween( thisText, startString, endString ):
    try:
    	if startString is 'start':
    		startIndex = 0
    	else:
    		startIndex = thisText.index( startString ) 
    	
    	if not (startIndex >= 0):
    		return 'Start delimiter not found'
    	else:
        	if startString is not 'start':
        		startIndex = startIndex + len( startString )
        
        returnText = thisText[startIndex:]


    	if endString is 'end':
    		return returnText
    	else:
    		endIndex = returnText.index( endString )

    	if not (endIndex >= 0):
    		return 'End delimiter not found'
    	else:
        	returnText = returnText[:endIndex]

        return returnText
    except ValueError:
        return "Value error"

script, first, second, third = argv

thisText = first
startString = second
endString = third

print textBetween( thisText, startString, endString )
Task: 4-rings or 4-squares puzzle

C: #include <stdio.h>

#define TRUE 1
#define FALSE 0

int a,b,c,d,e,f,g;
int lo,hi,unique,show;
int solutions;

void
bf()
{
    for (f = lo;f <= hi; f++)
        if ((!unique) ||
           ((f != a) && (f != c) && (f != d) && (f != g) && (f != e)))
            {
            b = e + f - c;
            if ((b >= lo) && (b <= hi) &&
                   ((!unique) || ((b != a) && (b != c) &&
                   (b != d) && (b != g) && (b != e) && (b != f))))
                {
                solutions++;
                if (show)
                    printf("%d %d %d %d %d %d %d\n",a,b,c,d,e,f,g);
                }
            }
}


void
ge()
{
    for (e = lo;e <= hi; e++)
        if ((!unique) || ((e != a) && (e != c) && (e != d)))
            {
            g = d + e;
            if ((g >= lo) && (g <= hi) &&
                   ((!unique) || ((g != a) && (g != c) &&
                   (g != d) && (g != e))))
                bf();
            }
}

void
acd()
{
    for (c = lo;c <= hi; c++)
        for (d = lo;d <= hi; d++)
            if ((!unique) || (c != d))
                {
                a = c + d;
                if ((a >= lo) && (a <= hi) &&
                   ((!unique) || ((c != 0) && (d != 0))))
                    ge();
                }
}


void
foursquares(int plo,int phi, int punique,int pshow)
{
    lo = plo;
    hi = phi;
    unique = punique;
    show = pshow;
    solutions = 0;

    printf("\n");

    acd();

    if (unique)
        printf("\n%d unique solutions in %d to %d\n",solutions,lo,hi);
    else
        printf("\n%d non-unique solutions in %d to %d\n",solutions,lo,hi);
}

main()
{
    foursquares(1,7,TRUE,TRUE);
    foursquares(3,9,TRUE,TRUE);
    foursquares(0,9,FALSE,FALSE);
}




Go: package main

import "fmt"

func main(){
	n, c := getCombs(1,7,true)
	fmt.Printf("%d unique solutions in 1 to 7\n",n)
	fmt.Println(c)
	n, c = getCombs(3,9,true)
	fmt.Printf("%d unique solutions in 3 to 9\n",n)
	fmt.Println(c)
	n, _ = getCombs(0,9,false)
	fmt.Printf("%d non-unique solutions in 0 to 9\n",n)
}

func getCombs(low,high int,unique bool) (num int,validCombs [][]int){
	for a := low; a <= high; a++ {
		for b := low; b <= high; b++ {
			for c := low; c <= high; c++ {
				for d := low; d <= high; d++ {
					for e := low; e <= high; e++ {
						for f := low; f <= high; f++ {
							for g := low; g <= high; g++ {
								if validComb(a,b,c,d,e,f,g) {
									if !unique || isUnique(a,b,c,d,e,f,g) {
										num++
										validCombs = append(validCombs,[]int{a,b,c,d,e,f,g})
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return
}
func isUnique(a,b,c,d,e,f,g int) (res bool) {
	data := make(map[int]int)
	data[a]++
	data[b]++
	data[c]++
	data[d]++
	data[e]++
	data[f]++
	data[g]++
	return len(data) == 7
}
func validComb(a,b,c,d,e,f,g int) bool{
	square1 := a + b
	square2 := b + c + d
	square3 := d + e + f
	square4 := f + g
	return square1 == square2 && square2 == square3 && square3 == square4
}