tsrc/testing/tools/utils.pl
changeset 0 96612d01cf9f
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 
       
    17 my $utils_PL_Included = 1; 
       
    18 
       
    19 #------------------------------------------------------------------------------------
       
    20 # GetPathFileName
       
    21 #
       
    22 # Parameters:
       
    23 # 	$str
       
    24 #------------------------------------------------------------------------------------
       
    25 sub GetPathFileName
       
    26 {
       
    27     my ($str) = @_;
       
    28 
       
    29     my $startPos = rindex($str, "\\");
       
    30     if($startPos == -1)
       
    31     {
       
    32         $startPos = rindex($str, "/");
       
    33         return $str if($startPos == -1);
       
    34     }
       
    35 
       
    36     my $filename = substr($str, $startPos+1);
       
    37 
       
    38     return $filename;
       
    39 }
       
    40 
       
    41 #------------------------------------------------------------------------------------
       
    42 # GetPathDir
       
    43 #
       
    44 # Parameters:
       
    45 # 	$str
       
    46 #------------------------------------------------------------------------------------
       
    47 sub GetPathDir
       
    48 {
       
    49     my ($str) = @_;
       
    50 
       
    51     my $startPos = rindex($str, "\\");
       
    52     if($startPos == -1)
       
    53     {
       
    54         $startPos = rindex($str, "/");
       
    55         return $str if($startPos == -1);
       
    56     }
       
    57 
       
    58     my $filename = substr($str, 0, $startPos+1);
       
    59 
       
    60     return $filename;
       
    61 }
       
    62 
       
    63 #------------------------------------------------------------------------------------
       
    64 # RemoveWhiteSpaces
       
    65 #
       
    66 # Parameters:
       
    67 # 	$text
       
    68 #------------------------------------------------------------------------------------
       
    69 sub RemoveWhiteSpaces
       
    70 {
       
    71 	my ($text) = @_;
       
    72 	${$text} =~ s/\s+$//; #whitespaces in the end
       
    73 	${$text} =~ s/^\s+//; #whitespaces at the start
       
    74 }
       
    75 
       
    76 #------------------------------------------------------------------------------------
       
    77 # XmlReadyText
       
    78 #
       
    79 # Parameters:
       
    80 # 	$text
       
    81 #------------------------------------------------------------------------------------
       
    82 sub XmlReadyText
       
    83 {
       
    84 	my ($text) = @_;
       
    85 
       
    86 	my $txtlt = "<";
       
    87 	my $txtgt = ">";
       
    88 	${$text} =~ s/</$txtlt/g;
       
    89 	${$text} =~ s/>/$txtgt/g;
       
    90 
       
    91 	${$text} =~ s/Ä/&Auml/g;
       
    92 	${$text} =~ s/ä/&auml/g;
       
    93 	${$text} =~ s/Ö/&Ouml/g;
       
    94 	${$text} =~ s/ö/&ouml/g;
       
    95 }
       
    96 
       
    97 #------------------------------------------------------------------------------------
       
    98 # XmlToText
       
    99 #
       
   100 # Parameters:
       
   101 # 	$text
       
   102 #------------------------------------------------------------------------------------
       
   103 sub XmlToText
       
   104 {
       
   105 	my ($text) = @_;
       
   106 
       
   107 	$txtlt = "&lt;";
       
   108 	$txtgt = "&gt;";
       
   109 	${$text} =~ s/$txtlt/</g;
       
   110 	${$text} =~ s/$txtgt/>/g;
       
   111 
       
   112 	${$text} =~ s/&Auml/Ä/g;
       
   113 	${$text} =~ s/&auml/ä/g;
       
   114 	${$text} =~ s/&Ouml/Ö/g;
       
   115 	${$text} =~ s/&ouml/ö/g;
       
   116 }