stdin.readLineSync() can't handle special characters - dart

I'm a beginner in Dart. I want to write a program that takes an input and print it with some predefined text.
This is how my code looks like:
import 'dart:convert';
import 'dart:io';
main() {
print('What is your name?');
print('Hello ${stdin.readLineSync(encoding: utf8)}');
}
And this is the how the command line looks like:
What is your name?
Leó Takács
Hello Le Takcs
It's just delete all the special characters. I think the problem is with the readLineSync because I tried printing 'Leó' and it works that way. My Dart SDK version is 2.14.2 by the way.
Thanks for your help!

It works for me (on Linux in an rxvt-unicode terminal).
That suggests that the problem isn't necessarily in the Dart platform code, or at least it's platform specific.
What platform are you running on?
What console are you using?
Is the console in fact UTF-8, or is it Latin-1 or Windows-1252? Try changing to encoding: latin1 and see if it makes a difference.

Related

how can i import main functin of another dart file

How can I verify that a print is called for in dart unit tests?
I am writing a sample code for textbooks and want to try it out. There are many examples that use printing for simplicity. I want to run my unit tests to make sure the print is called with the correct input but I have a problem importing the main function in another dart file.
Thank you!
You can import any library, including a script with a main method. The problem is that your own script's main method shadows the import.
The solution is to import the library with a prefix:
import "other_library.dart" as testee;
void main() {
print("Testing something");
testee.main(); // Uses a prefixed name to avoid name conflict.
print("Testing done");
}

Import Pcaml grammar to extend OCaml's printer using camlp5

I want to create a printer extension for OCaml using camlp5. My code would look like the example of this tutorial but instead of creating my own extension of the grammar, I would like to use OCaml's grammar to parse a program.
For that, I would like to use the Pcaml module to parse the given string with OCaml's grammar. Unfortunately, each time I try to use it, I get the:
Required module 'Pcaml' is unavailable
This is the part of my code where I load and open modules, as well as part of the code that uses Pcaml:
#load "pa_extprint.cmo";;
#load "q_MLast.cmo";;
#load "pa_o.cmo";;
open Pcaml;;
open Pprintf;;
let pa_ocaml = Grammar.Entry.create Pcaml.gram "pcaml_gram";;
I tried multiple command to run the program, like for example:
ocamlc -pp camlp5o -I +camlp5 gramlib.cma <my_file>.ml
What do I need to be able to use Pcaml and Pcaml.gram?
I recommend to use ocamlfind to build and link your programs. The only reason for newcomer against it, is that thing could become buggy when you use Windows without WSL. The compilation command without error is below
ocamlfind c -syntax camlp5o -package camlp5 -linkpkg a.ml
#load "pa_extprint.cmo";;
#load "q_MLast.cmo";;
#load "pa_o.cmo";;
open Pcaml;;
open Pprintf;;
let pa_ocaml : int Grammar.Entry.e = Grammar.Entry.create Pcaml.gram "pcaml_gram";;
FYI, your #load commands can and should be replaced by specifying right ocamlfind's packages.

TextMobject doesn't work on Jupyter-Manim

I am currently using jupyter-manim since it is the most efficient way for me to use manim. I'm running my code on Kaggle and every time I use TextMobject in manim, it outputs an error that says Latex error converting to dvi. See log output above or the log file: media/Tex/54dfbfee288272f0.log. I've tried TexMobject and Text function, but only the Text function works. The Text function is limited however, and I'm not sure how to change the font. Is there a way to fix this or is it something that comes with using jupyter-manim? It seems that all the other functions work such as drawing shapes, animating scenes, etc.
%%manim
class Text(Scene):
def construct(self):
first_line = TextMobject('Hi')
second_line = TexMobject('Hi')
#Only one that works
third_line = Text('Hi')
I tried your Manim program and it worked as expected for me. I would try making sure
include from manimlib.imports import * in your first line (importing Manim library)
include self.play(...) so you can see them
I think you already have these, but I'm putting them in case you don't.
You may also be getting the error because you do not have a LaTeX distribution installed on your system (i.e. MikTex or Texlive).
I think part of your problem may be the name of the class you chose. I had problems with your code until I changed the name from Text to TextTest. Here is a minimally working example that works fine in my Jupyter notebook (after running import jupyter_manim of course).
%%manim TextTest -p -ql
from manim import *
class TextTest(Scene):
def construct(self):
first_line = TextMobject('Hi 1')
second_line = TexMobject('Hi 2').shift(DOWN)
third_line = Text('Hi 3').shift(UP)
self.add(first_line)
self.add(second_line)
self.add(third_line)
self.wait(1)
Also, you should be aware that TextMobject and TexMobject have been deprecated.

How to tell if a character code represents a printable character in Dart?

Is there a way to tell if a character is printable in Dart?
Similar to unicode.IsPrint() in go.
See: https://golang.org/pkg/unicode/#IsPrint
Note - this does need to support non-latin characters.
I couldn't find any existing way to do this, so I ported golang's strconv.IsPrint() function.
See: https://github.com/xxgreg/dart_printable_char
To use it, first add the dependency to your pubspec.yaml.
dependencies:
printable_char:
git: git://github.com/xxgreg/dart_printable_char.git
Then import the library and use it.
import 'package:printable_char/printable_char.dart';
main() {
bool x = isPrintable('x'.codeUnitAt(0));
print(x);
}

Iconv.conv in Rails application to convert from unicode to ASCII//translit

We wanted to convert a unicode string in Slovak language into plain ASCII (without accents/carons) That is to do: č->c š->s á->a é->e etc.
We tried:
cstr = Iconv.conv('us-ascii//translit', 'utf-8', a_unicode_string)
It was working on one system (Mac) and was not working on the other (Ubuntu) where it was giving '?' for accented characters after conversion.
Problem: iconv was using LANG/LC_ALL variables. I do not know why, when the encodings are known, but well... You had to set the locale variables to something.utf8, for example: sk_SK.utf8 or en_GB.utf8
Next step was to try to set ENV['LANG'] and ENV['LC_ALL'] in config/application.rb. This was ignored by Iconv in ruby.
Another try was to use global system setting in /etc/default/locale - this worked in command line, but not for Rails application. Reason: apache has its own environment. Therefore the final solution was to add LANG/LC_ALL variables into /etc/apache2/envvars:
export LC_ALL="en_GB.utf8"
export LANG="en_GB.utf8"
export LANGUAGE="en_GB.utf8"
Restarted apache and it worked.
This is more a little how-to than a question. However, if someone has better solution I would like to know about it.
You can try unaccent approach instead.

Resources