Re: [Vala] Handling strings



Hi Al,

On 19.04.2017 15:04, Al Thomas wrote:

You've added 'const'. It should be:

private string ENTITY_FILE_LOCAL = {get {_filename =
 publication_title + ENTITY_FILE_SUFFIX; return _filename;}}

Constants do not change during the running of the program. They can, however,
be concatenated at compile time. So you could do:
private const string PATH = DIRECTORY_SEPARATOR_CHAR + AUTHOR_GROUP;

If the field is changeable during the running of the program then it shouldn't
be marked as 'const'.
I tried it out:
    private string _filename;
    private string _path;
    private string entity_file_suffix = ".ent";
    private string entity_file_local = {get {_filename =
publication_title + entity_file_suffix; return _filename;}}
    private string project_dir = {get {_path = target_dir +
Path.DIR_SEPARATOR + publication_title + Path.DIR_SEPARATOR +
create_language; return _path;}}

But got the same compiler error:
core/create_publication_core.vala:52.42-52.42: error: syntax error,
expected `}'
        private string entity_file_local = {get {_filename =
publication_title + entity_file_suffix; return _filename;}}
                                                ^
core/create_publication_core.vala:53.36-53.36: error: syntax error,
expected `}'
        private string project_dir = {get {_path = target_dir +
Path.DIR_SEPARATOR + publication_title + Path.DIR_SEPARATOR +
create_language; return _path;}}
By the way, GLib has a constant already for directory separator:
https://valadoc.org/glib-2.0/GLib.Path.DIR_SEPARATOR.html
Good point. Thank you, i'll changed it.

Greetings
Sascha

-- 
Sascha Manns
Maifeldstraße 10
56727 Mayen

P: +49-2651-4014045
W: http://saigkill.tuxfamily.org


Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]