print() public method

public print ( L level, object s ) : void
level L
s object
return void
Example #1
0
    [Test] public void delayed_string()
    {
	WvLog.maxlevel = WvLog.L.Debug1;
	var log = new WvLog("foo", WvLog.L.Debug2);
	
	b = true;
	log.print(new WvDelayedString(badrender));
	WVPASS(b);
	b = false;
	log.print(WvLog.L.Debug1, new WvDelayedString(goodrender));
	WVPASS(b);
	b = true;
	log.print(WvLog.L.Debug2, new WvDelayedString(badrender));
	WVPASS(b);
    }
Example #2
0
    static void do_request(WvHttpRequest req, Stream s)
    {
	WvLog log = new WvLog("do_request");
	log.print("Handling...\n");
	foreach (KeyValuePair<string,string> p in req.headers)
	    log.print("Header: '{0}' = '{1}'", p.Key, p.Value);
	
	using (StreamWriter w = new StreamWriter(s))
	{
	    w.WriteLine("HTTP/1.0 200 OK");
	    w.WriteLine("Content-type: text/plain");
	    w.WriteLine("");
	    w.WriteLine("Hello world!  Your path was '{0}'",
			req.path);
	    w.WriteLine("Query string: '{0}'", req.query_string);
	}
    }
Example #3
0
    static IEnumerable contprint(WvLog log, WvStream s, string prefix)
    {
	int i = 0;
	while (s.ok)
	{
	    i++;
	    string str = s.read(128).FromUTF8();
	    log.print("{0}#{1}: {2}\n", prefix, i, str);
	    yield return 0;
	}
    }
Example #4
0
    public static void Main()
    {
	{
	    Console.WriteLine("stdout works.");
	    Console.OpenStandardError().write("stderr works.\n".ToUTF8());
	    
	    WvLog log = new WvLog("main");
	    log.print("Hello");
	    log.print(" world!\n");
	    
	    WvStream s1 = new WvTcp("localhost", 80);
	    WvStream s2 = new WvTcp("localhost", 80);
	    s1.onreadable += contprint(log, s1, "\nA\n").ToAction();
	    s2.onreadable += contprint(log, s2, "\nB\n").ToAction();
	    s1.print("GET / HTTP/1.0\r\n\r\n");
	    s2.print("FOO / HTTP/1.0\r\n\r\n");
	    while (s1.ok || s2.ok)
		WvStream.runonce();
	    log.print("\n");
	    log.print("s1 err: {0}\n", s1.err.Short());
	    log.print("s2 err: {0}\n", s2.err.Short());
	}
    }
Example #5
0
    // Removes any matching enclosing parens from around a string.
    // E.g. "foo" => "foo", "(foo)" => "foo", "((foo))" => "foo", 
    // "((2)-(1))" => "(2)-(1)"
    public static string StripMatchingParens(string s)
    {
        WvLog log = new WvLog("StripMatchingParens", WvLog.L.Debug5);
        int len = s.Length;

        // Count the initial and trailing number of parens
        int init_parens = 0;
        while (init_parens < len && s[init_parens] == '(')
            init_parens++;

        int trailing_parens = 0;
        while (trailing_parens < len && s[len - trailing_parens - 1] == ')')
            trailing_parens++;

        // No leading or trailing parens means there can't possibly be any
        // matching parens.
        if (init_parens == 0 || trailing_parens == 0)
            return s;

        // Count all the parens in between the leading and trailing ones.
        bool is_escaped = false;
        int paren_count = init_parens;
        int min_parens = init_parens;
        for (int i = init_parens; i < s.Length - trailing_parens; i++)
        {
            if (s[i] == '(' && !is_escaped)
                paren_count++;
            else if (s[i] == ')' && !is_escaped)
                paren_count--;
            else if (s[i] == '\'')
                is_escaped = !is_escaped;

            if (paren_count < min_parens)
                min_parens = paren_count;
        }

        // The minimum number of outstanding parens found while iterating over
        // the string is the number of parens to strip.  Unless there aren't
        // enough trailing parens to match the leading ones, of course.
        min_parens = Math.Min(min_parens, trailing_parens);
        log.print("Trimming {0} parens\n", min_parens);
        return s.Substring(min_parens, len - 2*min_parens);
    }