ZSO-SPNFS_csv_coding.hpp File Reference

#include <string>
#include <cstdio>

Include dependency graph for ZSO-SPNFS_csv_coding.hpp:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::string read_csv_string (int fd)
 reads string that is send in quotes '"..."x' from file (e.p.
std::string make_csv_string (const std::string &str)
 make string in quotes '"..."x' from file (e.p.
std::string make_csv_string (const char *str, int len)
 make string in quotes '"..."x' from file (e.p.
std::string make_csv_string (long long l)
 make string in quotes '"..."x' from file (e.p.
ssize_t write (int fd, const std::string &str)
 writes STL string to file


Function Documentation

std::string make_csv_string ( long long  l  ) 

make string in quotes '"..."x' from file (e.p.

tcp stream) encoded in csv style. All quote characters '"' in string are doubled (changed into '""') like in csv format. After last quote character there is additionall char different from '"' to avoid misunderstanding of doubled quotes.

Definition at line 87 of file ZSO-SPNFS_csv_coding.hpp.

00087                                       {
00088     char buf[100];
00089     sprintf(buf,"\"%lld\",",l);
00090     return std::string(buf);
00091 };

std::string make_csv_string ( const char *  str,
int  len 
)

make string in quotes '"..."x' from file (e.p.

tcp stream) encoded in csv style. All quote characters '"' in string are doubled (changed into '""') like in csv format. After last quote character there is additionall char different from '"' to avoid misunderstanding of doubled quotes.

Definition at line 67 of file ZSO-SPNFS_csv_coding.hpp.

00067                                                    {
00068     //I know it's not best effective implementation, but simple and sure. So enough for prototype ;).
00069     std::string ret;
00070     int i;
00071     ret.append(1,' ');
00072     ret.append(1,'"');
00073     for(i=0;i<len;i++)
00074         if( str[i] !='"')
00075             ret.append(1,str[i]);
00076         else
00077             ret.append("\"\"");
00078     ret.append(1,'"');
00079     ret.append(1,',');
00080     return ret;
00081 };

std::string make_csv_string ( const std::string &  str  ) 

make string in quotes '"..."x' from file (e.p.

tcp stream) encoded in csv style. All quote characters '"' in string are doubled (changed into '""') like in csv format. After last quote character there is additionall char different from '"' to avoid misunderstanding of doubled quotes.

Definition at line 46 of file ZSO-SPNFS_csv_coding.hpp.

Referenced by encoded::encoded(), logining(), service_client(), spnfs_write(), zso_hook_chdir(), zso_hook_close(), zso_hook_dir(), zso_hook_exit(), zso_hook_mkdir(), zso_hook_open(), zso_hook_pos(), zso_hook_pwd(), zso_hook_read(), zso_hook_seek(), zso_hook_size(), zso_hook_touch(), zso_hook_trunc(), and zso_hook_write().

00046                                                {
00047     //I know it's not best effective implementation, but simple and sure. So enough for prototype ;).
00048     std::string ret;
00049     char ch;
00050     int i;
00051     ret.append(1,' ');
00052     ret.append(1,'"');
00053     for(i=0;i<str.size();++i)
00054         if( (ch=str[i]) !='"')
00055             ret.append(1,ch);
00056         else
00057             ret.append("\"\"");
00058     ret.append(1,'"');
00059     ret.append(1,',');
00060     return ret;
00061 };

Here is the caller graph for this function:

std::string read_csv_string ( int  fd  ) 

reads string that is send in quotes '"..."x' from file (e.p.

tcp stream) encoded in csv style. All quote characters '"' in string should be doubled (changed into '""') , the same as in csv format. After last quote character there must be at least one char different from '"' to avoid misunderstanding of double quotes '""'.
Begin "This is example ""encoded"" data", END .
There also can be a lot of data before beginning quote.

Definition at line 13 of file ZSO-SPNFS_csv_coding.hpp.

Referenced by getll(), getstr(), logining(), hooks_container::operator<<(), spnfs_connect(), zso_hook_chdir(), zso_hook_close(), zso_hook_dir(), zso_hook_mkdir(), zso_hook_open(), zso_hook_pos(), zso_hook_read(), zso_hook_seek(), zso_hook_size(), zso_hook_touch(), zso_hook_trunc(), and zso_hook_write().

00013                                  {
00014     char ch='x', prevch='x';
00015     std::string ret;
00016     int retint;
00017     while(ch!='"'){
00018         if((retint=read(fd,&ch,1))<=0){ fprintf(stderr,"read from socket. (Connection closed?)"); exit(EXIT_FAILURE); };
00019     };
00020     while(1){
00021         if((retint=read(fd,&ch,1))<=0){ fprintf(stderr,"read from socket. (Connection closed?)"); exit(EXIT_FAILURE); };
00022         //printf("%3d >(%c,%c) %s\n", retint, prevch, ch, ret.c_str());
00023         if(retint==1){
00024             if( prevch != '"' ){
00025                 if(ch!='"') { 
00026                     ret.append(1,ch);
00027                 } else prevch='"';
00028             } else {
00029                 if(ch=='"'){
00030                     ret.append(1,'"');
00031                     prevch='x';
00032                 } else break;
00033             };
00034         };
00035     };
00036 #ifdef DEB
00037     printf("read_csv_string() -> %s\n", ret.c_str());
00038 #endif
00039     return ret;
00040 }; 

Here is the caller graph for this function:

ssize_t write ( int  fd,
const std::string &  str 
) [inline]

writes STL string to file

Definition at line 94 of file ZSO-SPNFS_csv_coding.hpp.

Referenced by getll(), getstr(), logining(), main(), service_client(), snd(), spnfs_write(), zso_hook_chdir(), zso_hook_close(), zso_hook_dir(), zso_hook_exit(), zso_hook_mkdir(), zso_hook_open(), zso_hook_pos(), zso_hook_pwd(), zso_hook_read(), zso_hook_seek(), zso_hook_size(), zso_hook_touch(), zso_hook_trunc(), and zso_hook_write().

00094                                                    {
00095 #ifdef DEB
00096     std::string tmp(str); printf("write() -> %s\n", tmp.c_str());
00097 #endif
00098     return write(fd, str.data(), str.size() );
00099 };

Here is the caller graph for this function:


Generated on Mon Jan 21 12:09:53 2008 for ZSO - Simple Prototype of Network File System by  doxygen 1.5.4